Display all custom post types on front page
-
Hello world
I’ve set up 3 custom post types and I want them to be displayed on my front page (I’m using the portfolium theme by wpshower).
Right now the front page displays only the first one.Here is the code that displays the posts on the front page:
<?php $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); query_posts(array('post_type' => 'custom_post_1', 'custom_post_2', 'custom_post_3' => $term->slug, 'posts_per_page' => -1)); ?>
As I said earlier this code displays only the first custom post type (custom_post_1).
I’ve managed to get all the custom posts displayed using the code below in my functions.php, but this also get them displayed on the pages that are supposed to show only a certain custom post.add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_front_page() && false == $query->query_vars['suppress_filters'] ) $query->set( 'post_type', array( 'custom_post_1', 'custom_post_2', 'custom_post_3' ) ); return $query; }
The code for the custom posts page is this one:
<?php $type = 'custom_post_1'; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args=array( 'post_type' => $type, 'post_status' => 'publish', 'paged' => $paged, 'posts_per_page' => -1, 'caller_get_posts'=> 1 ); $temp = $wp_query; // assign original query to temp variable for later use $wp_query = null; $wp_query = new WP_Query(); $wp_query->query($args); ?>
Please help ??
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Display all custom post types on front page’ is closed to new replies.