wp query – get_posts() function does not honor correct post type

Question

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?

0
Aakash Chakravarthy 5 months 2023-07-07T14:54:09-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse