I’m registering multiple custom post types. One is ‘news’, the second is lets say ‘notification’. I’m registering both (and many others) with:
news:
$labels = .. // leaving this blank for SO, shouldn't be of importance
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'news' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions' )
);
register_post_type( 'news', $args );
notification:
$labels = .. // leaving this blank for SO, shouldn't be of importance
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'notification' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions' ),
'can_export' => true,
'taxonomies' => array('employee'),
);
register_post_type( 'notification', $args );
}
If I try to get for instance ‘news’ and ‘post’ post types (or ‘news’ and ‘event’ etc) like this
$args = array(
'post_type' => array('news','post'),
);
$the_query = new WP_Query( $args );
it will do what it should: get all posts of the types given in post_type array param.
However, when I try to get any post type WITH ‘notification’ post type, it won’t return ‘notification’ post types. Examples I tried:
‘post_type’ => array(‘news’,’post’), // news AND posts get returned
‘post_type’ => array(‘news’,’notification’), // news get returned, but not notifications
‘post_type’ => array(‘post’,’notification’), // only posts get returned
When passing only ‘notification’ post type I get the posts returned as I should:
‘post_type’ => array(‘notification’), // I get all notifications
Why won’t I receive any post of type ‘notification’ if any other post type is present in post_type array? There must be something ridiculously obvious I’m missing here.
The only difference when registering news and notification is ‘can_export’ and ‘taxonomies’ but that is not it (tried commenting this out for notification)
Thank you
UPDATE
Ok so I think I have the culprit: Polylang Plugin. If deactivated, this works as it should. Any ideas?!
OK, I got it. Absolutely ridiculous as expected.
One of the custom post types was not translated and checked in Polylang Settings because it was added after the plugin was configured.
Damn.