Slow queries on a huge database

As @milo said in the comments, the cat parameter (and similar parameters in other hierarchical taxonomies) will make the query look in subcategories as well. If you do not want that to happen use the category__in parameter. As for the general slowness, it is hard to guess, but it depends on your DB server performance … Read more

How to extract specific post

As noted in the documentation meta_value, when not used inside a meta query, needs to be a string. Normally if you want to query based on multiple meta values you need to add a meta_query argument. But also as noted in the documentation regarding value: It can be an array only when compare is ‘IN’, … Read more

WP_Query() order by post content lenght?

As Tom has said in his comment, there is no option for WP_Query for ordering posts by their word count/length. If you wanted to do this then you would have to firstly store the word count or length of each post as post meta. Once this was stored, you could then use WP_Query like so: … Read more

Dynamic User Id

You can use get_the_author_meta() which returns the requested data of the author of the current post. If you’re on the author archive page (e.g. author.php) that will be the ID of the user whose profile you are on. get_the_author_meta( ‘ID’ );

Order by empty custom field

There are two solutions for that: 1. Make sure that all posts have that field set. You can do this easily – just use save_post hook and set it to default value. (You should also add default values for already existing posts that don’t have that field set.) 2. Use a little bit modified query … Read more

WP_Query ignoring tax_query when is_singular

You can always use posts_clauses filter and add processing for tax_query in there (you don’t even need to write your own SQL): function filter_single_with_tax_queries( $clauses, $query ) { global $wpdb; if ( $query->is_singular ) { $query->parse_tax_query( $query->query_vars ); $tax_clauses = $query->tax_query->get_sql( $wpdb->posts, ‘ID’ ); $clauses[‘join’] .= $tax_clauses[‘join’]; $clauses[‘where’] .= $tax_clauses[‘where’]; } return $parts; } add_action( … Read more