order by numeric value for meta value
you need to use ‘orderby’ => ‘meta_value_num’, also if you are ordering dates, the best advice is to put them in an easy to order way such as 2012-12-31
you need to use ‘orderby’ => ‘meta_value_num’, also if you are ordering dates, the best advice is to put them in an easy to order way such as 2012-12-31
Please reference the Codex entry for post/page parameters for WP_Query(). The ‘p’ parameter takes a single post ID, as an integer. To pass an array of posts, you need to use ‘post__in’: $myarray = array(144, 246); $args = array( ‘post_type’ => ‘ai1ec_event’, ‘post__in’ => $myarray ); // The Query $the_query = new WP_Query( $args );
You won’t do much good just merging the arguments, you need to merge the resulting posts array and the post_count count. This works for me: //setup your queries as you already do $query1 = new WP_Query($args_for_query1); $query2 = new WP_Query($args_for_query2); //create new empty query and populate it with the other two $wp_query = new WP_Query(); … Read more
$num = $obj_name->post_count; Reference: wp_query
I’m going to answer this myself, but it was the very clever @simonwheatley of Code for the People that solved this one for me. Instead of using wp_reset_postdata() or wp_reset_query(), you can use the following: $publication->reset_postdata(); Where $publication is your query object. The working code now looks like: $publication = new WP_Query( array( ‘connected_type’ => … Read more
Please try this: $args = array( ‘category_name’ => ‘cat1’, ‘posts_per_page’ => 5, ‘orderby’ => ‘rand’, ); $pc = new WP_Query( $args ); where ‘rand’ should give you a random order of your posts. For more info check out the Codex on WP_Query order parameters here.
global $wp_query; echo $wp_query->max_num_pages; This shows the number of pages for the current query. If you want to determine the actual number of posts found by the current query, you may use $wp_query->found_posts Source:- http://codex.wordpress.org/Class_Reference/WP_Query
The simplest way is to add the action right before the query and remove it immediately after. add_action(‘pre_get_posts’, ‘some_function_in_functionsphp’); $my_secondary_loop = new WP_Query(…); remove_action(‘pre_get_posts’, ‘some_function_in_functionsphp’); if( $my_secondary_loop->have_posts() ): while( $my_secondary_loop->have_posts() ): $my_secondary_loop->the_post(); //The secondary loop endwhile; endif; wp_reset_postdata(); EDIT Another technique you can use is to set your own query var and check for that … Read more
By default, WP_Query returns the standard WP_Post objects for the posts being queried. I believe with some clever rewrite and use of the filters given in WP_Query you can add objects to the returned WP_Post objects array. Will this be performant? In my opinion, it will hurt performance more as you will need to join … Read more
Try ‘post__in’ => array(0) Simple and to the point. Update: ‘post__in’ => empty( $include ) ? [ 0 ] : $include,