I want to return all parent events from the posts-table (where post_parent = 0).
This works absolutely fine when I run a raw sql query but when I run a wp_query in my PHP class I will only receive 8 rows from the WP's posts-table. I turned cache off and tried other things but I can't get my head around why not all 23 rows are returned by the WP query. Thanks for any hint.
Raw SQL Query (works fine - 23 rows):
select * from wp_posts
where post_type = 'tribe_events' and post_parent = 0 and post_status = 'publish';
WP Query (only returns 8 rows which is wrong)
$args = array(
'post_type' => 'tribe_events',
'posts_per_page' => -1,
'post_status' => 'publish',
'post_parent' => 0
);
$evts = new WP_Query($args);
There are two things I would try to understand the cause of your problem.
(1.) Use 'suppress_filters' = true to insure that no filters are modifying your query.
$args = array(
'post_type' => 'tribe_events',
'posts_per_page' => -1,
'post_status' => 'publish',
'post_parent' => 0,
'suppress_filters' => true
);
$evts = new WP_Query($args);
(2.) Dump the actual MySQL query that WordPress is using by using the filter 'posts_request'.
add_filter( 'posts_request', function( $sql ) {
error_log( 'SQL=' . $sql );
return $sql;
} );
Of course, for this filter to work 'suppress_filters' must be false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With