Pagination for search results of custom post type [duplicate]

You need to set your paged arg in your $args array: $listing_args = array( ‘post_type’ => ‘business’, ‘posts_per_page’ => 10, ‘meta_key’ => ‘listing_num’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ‘offset’ => ($paged -1) * 10, ‘paged’ => $paged, // <- tell the query what page we are on. ‘tax_query’ => ……etc ); And then use … Read more

Loop categories by recent post

First set a function to be used later with a usort to sort the categories by date of most recent post: function orderByDate( $a, $b ) { return strtotime($a[‘date’]) – strtotime($b[‘date’]); } Get your categories as you were doing: $args = array( ‘hide_empty’=> 1 ); $categories = get_categories($args); $categoriesWithDates = array(); // Create an array … Read more

How to Order By Two Custom Fields?

You can try this by using meta query to filter results and then adding orderby to order results. Below arguments should work $args = array( ‘post_type’ => array(‘post’, ‘video’), ‘meta_key’ => ‘pp_like_count’, ‘orderby’ => ‘meta_value_num’, “meta_query” => array( array( “key” => “pp_lang”, “value” => “english”, “type” => “CHAR”, “compare” => “=” ), ), );

WP Query and date format

For those who experienced the same problem, I finally found a way to do the sort. First I created an extra CMB like this : $cmb->add_field( array( ‘id’ => $prefix . ‘session_gooddatebegin’, ‘type’ => ‘hidden’, ) ); Then I created an action using save_post. If the CPT “session” is being updated, thanks to $update, I … Read more

WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?

Your code is invalid (syntax error, missing closing array and semi-colon), and incorrectly nested – if you were to properly indent your code, you’d have something like: $args = array( ‘tag’ => ‘tag-AAA,tag-BBB’, array ( ‘orderby’ => array( ‘title’ => ‘ASC’, ‘post_date’ => ‘DESC’, ) ), ); See how orderby isn’t actually a property of … Read more

Pagination in html table is not working

You should get total and result array separately. Total is to create the page numbers and result array will give you limited data for each pages. Refer the below code. if (isset($_POST[‘list_position’]) && $_POST[‘list_position’] != ‘Select by Position’){ $list_position= $_POST[‘list_position’]; $totalPosition= $wpdb->get_var(“SELECT count(id) FROM resume_databank WHERE position= ‘” . $list_position . “‘ ORDER BY position … Read more