Home > Mobile >  Show posts and custom post types
Show posts and custom post types

Time:07-20

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

CodePudding user response:

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.

More info here

CodePudding user response:

?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 and if you wanna fetch the custom post type you can pass the name of the custom post type like 'movies' 'courses' whatever your custom post type name is in your wordpress.

  • Related