WP_Query meta value order is not working

If the variable you are storing in meta_value were an integer, you would not be able to store it as ’02’. So, apparently, your are storing a string. This indeed gives different orders depending on whether you store ’02’ or ‘2’, as is described under meta_value in the codex on WP_Query. So, as the codex … Read more

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

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