Helllo,
I want to show posts and custom post types , can I change post_type in query as array(‘post’,’custom_post_type’)
function get_posts( $args = null ) {
$defaults = array(
'numberposts' => 5,
'category' => 0,
'orderby' => 'date',
'order' => 'DESC',
'include' => array(),
'exclude' => array(),
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'suppress_filters' => true,
);
thanks in advance
2
Answers
You can add the
post_type
as a string (single type) or an array (multiple types).Example:
movie
andbook
above are Custom Post Types.If you want all post types just:
The above retrieves any type except
revisions
and types withexclude_from_search
set to true.More info here
If you want to fetch the WordPress posts you can write
post
in thepost_type
parameter. If you want to fetch the custom post type you can pass the name of the custom post type likemovies
orcourses
, to match whatever your custom post type name is in WordPress.