Reputation: 17
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
Upvotes: 0
Views: 386
Reputation: 785
<?php
$args = array(
'post_type' => 'my_post_type',
'post_status' => 'publish',
'posts_per_page' => -1
);
?>
If you want to fetch the WordPress posts you can write post
in the post_type
parameter. If you want to fetch the custom post type you can pass the name of the custom post type like movies
or courses
, to match whatever your custom post type name is in WordPress.
Upvotes: 0
Reputation: 857
You can add the post_type
as a string (single type) or an array (multiple types).
Example:
$args = array(
'post_type' => array( 'post', 'page', 'movie', 'book' )
);
movie
and book
above are Custom Post Types.
If you want all post types just:
$args = array(
'post_type' => 'any'
);
The above retrieves any type except revisions
and types with exclude_from_search
set to true.
Upvotes: 1