0

Hi i am working on custom post types in wordpress presently we are using below code to display the custom posts, but the thing is the custom post types are keep on increasing,

add_action( 'pre_get_posts', 'add_my_post_types_to_query' );

function add_my_post_types_to_query( $query ) {
    if ( is_home() && $query->is_main_query() )
        $query->set( 'post_type', array( 'books', 'recipes', 'movie' ) );
    return $query;
}

from above query i am calling the posts from books,recipes and movie but due increase of post_types i cant add all the post types in the above query.

dose anybody have idea how to call all the posts from all post_types.

2 Answers 2

2
add_action( 'pre_get_posts', 'add_my_post_types_to_query' );

function add_my_post_types_to_query( $query ) {
  if ( is_home() && $query->is_main_query() )
    $query->set( 'post_type', 'any' );
  return $query;
}

refer to http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters

1
  • how to get only public post_types here is my script <?php query_posts('post_type=any'); ?> <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    – sunil
    Commented Jul 23, 2014 at 22:51
0

As far as I remember the appropriate query for all public post types is post_type equals string any.

You can use get_post_types() to retrieve a list, but be careful with arguments, since not post types are meant for public/front display.

1
  • From WP_Query's Codex Page: "'any' - retrieves any type except revisions and types with 'exclude_from_search' set to true." This also implicitly excludes attachment since it has the non-default post_status of "inherit".
    – mrwweb
    Commented Jul 24, 2014 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.