I'm fetching all posts of a specific custom post type like below.
print_r(ANCR_POST_TYPE);
$announcements = array();
$announcement_posts = get_posts(array(
'post_type' => ANCR_POST_TYPE, // Post type is set to "announcer"
'posts_per_page' => 2,
'orderby' => 'menu_order',
'order' => 'asc',
'post_status' => 'publish'
));
print_r($announcement_posts);
But the get_posts()
function returns posts which are not of type ANCR_POST_TYPE
announcer
Array
(
[0] => WP_Post Object
(
[ID] => 104
[post_author] => 1
[post_date] => 2023-07-07 18:15:23
[post_date_gmt] => 2023-07-07 18:15:23
[post_content] => This is an event
[post_title] => Event
[post_excerpt] =>
[post_status] => publish
[comment_status] => open
[ping_status] => closed
[post_password] =>
[post_name] => event
[to_ping] =>
[pinged] =>
[post_modified] => 2023-07-07 18:15:23
[post_modified_gmt] => 2023-07-07 18:15:23
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://example.com/?post_type=tribe_events&p=104
[menu_order] => 0
[post_type] => tribe_events <----- posts of type "tribe_events" is retreived instead of type "announcer"
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
)
This is seen only on the tags archive page of "tribe_events" post type.
Any idea on when this could happen?
pre_get_posts
filter in your sites code? Functions on that filter can modify parameters that are fed intoWP_Query
and its wrapper functions such asget_posts
pre_get_posts
filters sometimes do this if they don't have enough conditions/checks to prevent leakage. You could use the suppress filters option but then that means it's impossible to filter/extend that query and you break compatibility with caching plugins and other things, e.g. no more elastic search support. My suspicion is that the filter the user has doesn't check if it's the main query or not