How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?

Hopefully you’ve figured this out by now, but if you haven’t you should be able to use the “posts_orderby” filter to dial in a specific order for your query. I’m not going to give a full solution here, but you can refer to this post for more: http://mitcho.com/blog/how-to/external-orders-in-wordpress-queries/ EDIT: Here’s the Documentation – basically you … Read more

Display posts of the last 7 days

In addition to birgire’s solution, as of WordPress 3.7, you can use Date parameters. Your arguments would look like this to filter posts from the last 7 days: $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, // Using the date_query to filter posts from last week ‘date_query’ => … Read more

Using WP_Query to Query Multiple Categories with Limited Posts Per Category?

What you want is possible but will require you to delve into SQL which I like to avoid whenever possible (not because I don’t know it, I’m an advance SQL developer, but because in WordPress you want to use the API whenever possible to minimize future compatibility problems related to future potential database structure changes.) … Read more

how to query posts by category and tag?

Edit: See below for proper way to query category and tag intersections. global $wp_query; $args = array( ‘category__and’ => ‘category’, //must use category id for this field ‘tag__in’ => ‘post_tag’, //must use tag id for this field ‘posts_per_page’ => -1); //get all posts $posts = get_posts($args); foreach ($posts as $post) : //do stuff endforeach;

Why query_posts() isn’t marked as deprecated?

Essential question Let’s dig into the trio: ::query_posts, ::get_posts and class WP_Query to understand ::query_posts better. The cornerstone for getting the data in WordPress is the WP_Query class. Both methods ::query_posts and ::get_posts use that class. Note that the class WP_Query also contains the methods with the same name: WP_Query::query_posts and WP_Query::get_posts, but we actually … Read more