Is there a way to join WP_Query without a filter?

No. There isn’t. The only way to add custom joins to a WordPress query is through the posts_join filter or posts_clauses filter, which contains all the parts of the query. Those filters receive the WP_Query object as a parameter though, which allows you to create custom arguments for WP_Query that will affect the query. function … Read more

Where is the extra SQL fields coming from?

There is nothing wrong, the reason the data is there is to handle the problem of ordering when 2 posts have the same value for their meta key. ORDER BY EventStartDate DESC, wp_posts.post_date DESC Here we see that post data is not the only thing it’s ordering on, EventStartDate is what’s being ordered on, and … Read more

Passing an array into WP_Query as a variable

First of all, you have a typo in your code. The variable with post IDs is called post_id_array, but your foreach loop uses post_ids_array (ids instead of id). When you fix this, then there’s one more problem. Meta query param should be an array of queries and each query should be an array. But your … Read more

Post not populating for custom post type based on category selection

But this part is not executing → $args = array( ‘category_name’ => $taxonomy, ‘post_type’ => ‘video’, ‘posts_per_page’ => -1, It probably is. It’s just wrong. If you want to query posts by terms in a custom taxonomy you need to add a taxonomy query: $args = array( ‘post_type’ => ‘video’, ‘posts_per_page’ => -1, ‘tax_query’ => … Read more

Trouble building a custom WP_query

There’s an action you could hook into. It’s called pre_get_posts and it lets you alter the query before the query is run. This code should be placed into your functions.php file. function my_exclude_category( $query ) { if ( $query->is_singular(‘post’) && $query->is_main_query() ) { $query->set( ‘cat’, ‘-10’ ); } } add_action( ‘pre_get_posts’, ‘my_exclude_category’ ); Please note. … Read more

show posts with range meta key

You can compare BETWEEN in the meta_query and you need to set the type too for NUMERIC. For example $args = array( ‘post_type’ => ‘my_custom_post_type’, ‘meta_key’ => ‘age’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘age’, ‘value’ => array( 5, 10 ), ‘compare’ => ‘BETWEEN’, ‘type’ => ‘NUMERIC’ ) )); … Read more