List the 5 most recent child pages

Assuming you know (or know how to get) the $id (as an integer) of the parent post, use the post_parent parameter: $albums = new WP_Query(array( ‘post_type’ => ‘gallery’, ‘posts_per_page’ => 6, ‘post_parent’ => $id )); Edit Based on this comment: I don’t know the parent post. I want to list the most recent child pages … Read more

Custom Order in WP Query

Chain the filters: if ( ‘include’ == $query->query_vars[‘orderby’] ) add_filter( ‘posts_orderby’, /* … */ ); And in your orderby filter use: remove_filter( current_filter(), __FUNCTION__ );

Understanding the use of wp_reset_query();

When you call query_post it replaces the main query object with one of its own, but that isn’t desirable. If you want to return to the main query, you have to call wp_reset_query to do so whichr estores the original query. I’d advise strongly against the use of query_posts and instead suggest you use WP_Query. … Read more

WP_Query or get_posts?

get_posts() simply uses a WPQuery object and sets a few default values. In general the values it sets make it mildly more performant. But I wouldn’t worry to much about it. get_posts() is simplier so as a rule of thumb if you don’t need any of the more involved features of WP_Query (including pagination) – … Read more

Filter WordPress posts by between parameter

Tax Query Limits A Taxonomy Query in WordPress supports the following three arguments for the operator parameter: IN, NOT IN and AND. So it basically can’t do what you’re trying to do. Not even with advanced (tax_query) Queries. Meta Query and possibilities You’ll want to move your concept a bit and work with post meta … Read more

Get post ID’s from one query and exclude from another

While running the loop of the first query, just collect the IDs into an array. Example: // define your first query’s arguments $args1 = array( … your first query args ); $query1 = new WP_Query($args1); while ( $query1->have_posts() ): $query1->the_post(); // this is your loop. Do whatever you want here // add this in the … Read more