Filter posts of custom post type by meta key in (List All Section)
You can use the action pre_get_posts . Just make sure to check is_post_type_archive(‘question’) and is_admin() to prevent affect queries in the whole website.
You can use the action pre_get_posts . Just make sure to check is_post_type_archive(‘question’) and is_admin() to prevent affect queries in the whole website.
Your best bet is not to run a bunch of queries but to loop through your data once to organize it then a second time to display it. Below is the logic you need. The exact code will depend on your data set. $events = array(); $posts = WP_Query( $args ); foreach ( $posts as … Read more
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
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
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” => “=” ), ), );
If I get it right you are storing this data in user meta. WP_Query would have no remote idea how to retrieve that, since it’s only aware of post meta. The two are completely separate and there is no native way to involve one in queries for another. Likely you will have to do this … Read more
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
With is_paged you are testing whether a post has been divided in parts using the QuickTag. But with next_posts_link you are pointing to the next page of posts. So you probably need another test.
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
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