Nested meta_query with multiple relation keys

The question was for WordPress 3.0, but just in case someone has the same question for a more recent version, from WordPress Codex: “Starting with version 4.1, meta_query clauses can be nested in order to construct complex queries.” https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters So, that query should work on the current WordPress version.

Custom query with orderby meta_value of custom field

You can define the meta key for orderby parameter using the old method (I tested on WP 3.1.1)… query_posts( array( ‘post_type’ => ‘services’, ‘order’ => ‘ASC’, ‘meta_key’ => ‘some_key’, ‘orderby’ => ‘meta_value’, //or ‘meta_value_num’ ‘meta_query’ => array( array(‘key’ => ‘order_in_archive’, ‘value’ => ‘some_value’ ) ) ) );

posts_per_page no limit

-1 is your answer! Look for posts_per_page here. $args = array( ‘post_type’ => ‘post’, ‘cat’ => ‘22,47,67’, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘hide_empty’ => 1, ‘depth’ => 1, ‘posts_per_page’ => -1 ); Important caveat: This can result in a very huge query that can bring the site down. Do this only if you are … Read more

When to use WP_query(), query_posts() and pre_get_posts

You are right to say: Never use query_posts anymore pre_get_posts pre_get_posts is a filter, for altering any query. It is most often used to alter only the ‘main query’: add_action(‘pre_get_posts’,’wpse50761_alter_query’); function wpse50761_alter_query($query){ if( $query->is_main_query() ){ //Do something to main query } } (I would also check that is_admin() returns false – though this may be … Read more