Articles of wp query

How would I format a query that depends on post parent taxonomy

I’m trying to do a custom query which is outside the scope of a single WP_Query, I think I should be using $wpdb but my SQL is a bit ropey. Also I only need the post IDs returned not post objects. Basically I need to find all posts with a meta value of $foobar whose […]

Display posts if a custom field value is equal to another custom field value

I have 2 custom post types “Shops” and “Restaurants”. Each of these have custom fields associcated with them. For example, One field in Shops is “Shop ID” and one in Restaurants is “Restaurant ID”. I want to query both Custom Post Types and if Shop ID is 20, I want to display all Restaurants with […]

Sort users by “birthday” using WP_User_Query

I have created user meta that holds user birthday (birthday). birthday is date field. Now i am trying to figure how to sort (get) all users that have birthday based on specific month. I have created drop menu that holds all the months. function users_months_dropdown() { ?> <select name=”month” id=”month” onchange=”” size=”1″> <option value=”01″>January</option> <option […]

Most popular post for last 7 days

I need to change the most popular post widgets with date restrictions. For an example, how should I get most popular posts(post_views_count) of last 7 days. original query, $popularposts = new WP_Query(‘showposts=10&meta_key=post_views_count&orderby=meta_value_num&order=DESC&ignore_sticky_posts=1’) then I changed that to, $args = array( ‘date_query’ => array( array( ‘after’ => ‘-7 days’ ) ), ‘showposts’ => 10, ‘ignore_sticky_posts’ => […]

How to pass many ids in post__in?

I need to pass many ids to the parameter post__in in args. This not work !!! Help me please. foreach ($rows as $obj) { $todos .= $obj->ID . “,”; } $ids = trim(trim($todos), “,”); # echo $ids output ——-> 613,647 $args = array ( ‘post_type’ => ‘professores’, ‘post__in’ => array($ids) <—– Don’t work ); How […]

Efficient way to update multiple post meta

I have managed to update post meta using update_post_meta(). However, the more posts I have, the more time it takes. I would like to minimize the time it takes to process say about 400 posts (although I am not too sure how long this will take). Currently my code looks like this: $numbers = range(1,100000); […]

Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts

UPDATE: The hook is working with “classic” WordPress filter (like post__in), so it’s probably a Posts2Posts issue. I’m still looking for suggestions if someone has any idea. ORIGINAL POST I’m trying to get all posts displayed by issue number in archive pages. Issues are a custom post type (linked with post2post, which is why I […]

WP_Query OR clause for tax_query and keywords

Is it possible to make an OR clause between tax_query and keywords? I’d like WP_Query to return posts if there is a tax_query match or a s keyword match.

Pagination causes error 404 when used with front-page.php

I am creating front-page.php. This page will display the latest featureed posts, and will also have pagination option to go to the previous featured posts. I wrote the code for frontpage as follows $args = array(); $args[‘post_type’] = ‘post’; $args[‘post_status’] = ‘publish’; $args[‘category_name’] = ‘featured’; $args[‘posts_per_page’] = 4 $args[‘paged’] = (get_query_var(‘page’)) ? get_query_var(‘page’) : 1; […]

WP_Query Group by Author and Order each group DESC

I’m trying to do a query where I get all the posts from a specific category, order/group them by author and in each group order the posts DESC. In the end the author with the newest post will be a the top of the output list. This is what I use now, but the posts […]