How can i display 3 post types in same page?

Make sure that your registration arguments for your post types have the public argument set to true or, alternately, publicly_queryable set to true and exclude_from_search set to false.

Then, modify your search query by hooking into the pre_get_posts action:

function filter_search( $query ) {
    $postTypes = array( 'post', 'post_type1-Movies', 'post_type2-Trailers', 'post_type3-Subtitrari' );

    //Here you can modify the $postTypes array, say to account for the value of $_REQUEST['post_type'] as set by your dropdown or some such.

    if ( $query->is_search ) {
        $query->set( 'post_type', $postTypes );
    }
    return $query;
}
add_action( 'pre_get_posts', 'filter_search' );

Now all of your custom post types will be included in search queries.

If you wish to group multiple post types relating to the same subject, however (i.e. a specific movie or some such), it may be wiser to only search the post-type of the primary subject (i.e. searching for “Battleship” would only search your movie post-type). Associating other post types with the subject could be done by storing the primary subject’s id in the meta-data for each associated item. This would allow you to query each of the other post types for associated data by simply searching for the primary subject’s id, ideally when displaying it from within the loop (i.e. when looping through the results of the “Battleship” search, query the trailers post type for items with a meta field, “movie” set to the ID of the movie post currently being processed).

Leave a Comment