Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 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

share|improve this answer
    
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 Jul 23 at 22:51

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.

share|improve this answer
    
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 Jul 24 at 0:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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