Posts

Showing posts from June, 2016

Get posts and featured Image via direct sql query

SELECT p1.*, wm2.meta_value FROM wp_posts p1 LEFTJOIN wp_postmeta wm1 ON( wm1.post_id = p1.id AND wm1.meta_value ISNOTNULLAND wm1.meta_key ="_thumbnail_id")LEFTJOIN wp_postmeta wm2 ON( wm1.meta_value = wm2.post_id AND wm2.meta_key ="_wp_attached_file"AND wm2.meta_value ISNOTNULL)WHERE p1.post_status="publish"AND p1.post_type="post"ORDERBY p1.post_date DESC

Get child pages from parent page id in wordpress

<?php
// Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
$child_pages = get_page_children( 46, $all_wp_pages );            // 46 is the parent page id
echo '<pre>' . print_r( $child_pages, true ) . '</pre>';
?>

Remove all the options of a select box and then add one option and select it with jQuery

$('#mySelect').empty().append('<option selected="selected" value="whatever">text</option>');For more details visit: Stackoverflow

Set global constants containing arrays using Codeigniter

You can use Codeigniter's constants file to store global arrays which can be used in multiple controllers or any where within your codeigniter's project scope. 
Problem: Apparently, constants can't hold arrays.
Solution: You can serialize your array and then put it into the constant.
For example,
# define constant, serialize array define ("FRUITS", serialize (array ("apple", "cherry", "banana"))); # use it $my_fruits = unserialize (FRUITS);OR # Define associative array define('DEFAULT_VENDOR_TYPE',serialize(array('elite'=>'Elite','featured'=>'Featured','premium'=>'Premium'))); # use it $vendor_type = unserialize (DEFAULT_VENDOR_TYPE);For more details visit: http://developer-paradize.blogspot.in/2013/08/how-to-set-global-constants-containing.html

Add order by query in datatable library codeigniter

Its very simple
Use: $this->db->order_by("column name", "desc");

For Example:

$this->db->order_by("cat_id", "desc");
$this->datatables->select('cat_id,cat_name,cat_desc,level,cat_icon')
->unset_column('cat_icon')
->add_column('Actions', get_buttons('$1'), 'cat_id')
->from('categories');

Add bootstrap pagination in codeigniter

To avoid loading each time in each controller we can place bellow config array in config folder with pagination.php file name.
<?php $config['per_page'] = 10; $config['use_page_numbers'] = TRUE; $config['full_tag_open'] = "<ul class='pagination'>"; $config['full_tag_close'] ="</ul>"; $config['first_link'] = '&larr; First'; $config['num_tag_open'] = '<li>'; $config['num_tag_close'] = '</li>'; $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>"; $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>"; $config['next_link'] = 'Next &raquo;'; $config['next_tag_open'] = "<li>"; $config['next_tagl_close'] = "</li>"; $config['prev_link…