How to change WP Query to display related posts

I wrote the code and it works but when I add another Query Loop block (latest posts) to that page it shows the related posts. That happens because although your filter callback is registered only when blockName is related-posts, the query_loop_block_query_vars hook still applies globally to all Query Loop blocks rendered after that. How do … Read more

WP_Query returns wrong post when searching by title?

We should be able to fix the query by doing this instead: $query = new \WP_Query([ ‘post_type’ => ‘location-data’, ‘posts_per_page’ => 1, ‘post_status’ => ‘publish’, ‘title’ => $title ]); This is because page is unnecessary and may not be the parameter you actually needed, paged would have been more appropriate, but it too is unnecessary. … Read more

WP_Query equivalent of SQL UNION ALL

You can run 2 wp_query, get the ids and pass those as the post__in parameter to a 3rd wp_query. Not efficient but will do the job. Or you can use a subquery and do it all with just one wp_query. Something like the following: add_filter( ‘posts_where’, ‘myprefix_posts_where’, 10, 2 ); new WP_Query([ ‘post_status’ => ‘publish’, … Read more

File not found.