i'm making modifications to a portfolio theme. the theme has the blog and portfolios. the portfolios are custom post types with their respective taxonomies. the theme homepage only displays one portfolio. that is, it only shows the posts for one custom post type. the theme displays the most recent posts for each category of the custom post type and creates a filter menu that is populated with the categories. this way a user can filter the displayed posts by category like "graphic design" and a JS script hides the posts that are not of that category. i need to mix the posts of all portfolios and the blog on the homepage. so i need to query all the recent posts from all portfolios and the blog, populate the filter menu with post types, and then pass that over to the JS script to hide the posts that are not of the selected post type.

i've managed to query all the recent posts from all portfolios and the blog, and populate the filter menu with post types using the code below: THE COMMENTED CODE IS THE ORIGINAL CODE, e.g. $terms

    'post_type' => array('post', 'test-bscm', 'test-btum', 'test-other', ),
    'posts_per_page' => 16
$temp = $wp_query; 
$wp_query = null;
$wp_query = new WP_Query();
/*$terms = get_terms($pcat);*/

//populate the filter with post types
$args=array(  'show_in_menu' => true);
$output = 'names';
$terms = get_post_types($args);

<!-- Portfolio Filters
================================================== -->

<?php if ($home_portfoliolayout=="No Categories") { 
    echo '<div class="sixteen columns row portfolio_filter" style="display: none;">';
} else if ($home_portfoliolayout=="Categories") {
    echo '<div class="sixteen columns row portfolio_filter">';
} ?>
        echo '<li><a class="portfolio_selector" data-group="all-group" href="#">'.__('All Projects', 'apex').'</a><span>|</span></li>';
        foreach ( $terms as $term ) {
            $filter_last_item = end($terms);
                echo '<li><a class="portfolio_selector" data-group="'.str_replace(' ', '-', $term).'" href="#">'.ucwords(str_replace('-', ' ', $term)).'</a><span>|</span></li>';
                echo '<li><a class="portfolio_selector" data-group="'.str_replace(' ', '-', $term).'" href="#">'.ucwords(str_replace('-', ' ', $term)).'</a></li>';
</div><div class="clear"></div>

i am able to see a 16 posts that represent the most recent posts to the blog, test bscm portfolio, test bum portfolio, and the test other portfolio. the filter shows: All Projects, Post, Pages, Test Bscm, Test Btum, and Test Other. i need to remove Pages from the results because it is not needed. here's the code to how the results are displayed and so how the JS script hides posts...

    <!-- Portfolio Teasers
================================================== -->

<div class="sixteen columns row <?php echo $folioteasers ?> portfolio">

    <?php if ($wp_query->have_posts()) : ?>
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

        $custom = get_post_custom($post->ID);
        $foliocatlist = get_the_term_list( $post->ID, $pcat, '', ', ', '' );
        $entrycategory = get_the_term_list( $post->ID, $pcat, '', '_', '' );
        $entrycategory = strip_tags($entrycategory);
        $entrycategory = strtolower($entrycategory);
        $entrycategory = str_replace(' ', '-', $entrycategory);
        $entrycategory = str_replace('_', ' ', $entrycategory);
        $entrytitle = get_the_title();
        $blogimageurl = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
            $blogimageurl = $templateurl.'/images/demo/460x272.jpg';

    <div class="<?php echo $foliocolumns ?> columns teaser all-group <?php echo $entrycategory ?>">
       <a href="<?php the_permalink(); ?>" data-text="&raquo; <?php _e('Visit Project', 'apex'); ?>" class="hovering"><?php echo '<img src="'.get_template_directory_uri().'/functions/thumb.php?src='.$blogimageurl.'&amp;h=272&amp;w=460&amp;zc=1" alt="" class="scale-with-grid" />'; ?></a>
       <div class="pluswrap">
           <a href="<?php the_permalink(); ?>" class="bigplus"></a>
           <div class="topline"><a href="<?php the_permalink(); ?>"><?php echo $entrytitle ?></a></div>
           <div class="subline"><?php echo $foliocatlist ?></div>

    <?php endwhile; ?>
    <?php else : ?>
    <div class="eleven columns row alpha">
        <p><?php _e('Oops, we could not find what you were looking for...', 'apex'); ?></p>
    <?php endif; ?>

    $wp_query = null; 
    $wp_query = $temp;

    <div class="clear"></div>
</div><div class="clear"></div>

as you can see it's based on the post category. so of course when i try to filter by one of the listed post types all results are hidden. so the solution is to associate the post id with its post type. i know it comes after the $custom = get_post_custom($post->ID); and i'll replace all that code for foliocatlist and entrycategory i just haven't found it in the codex. thanks.


If there's no significant reason that you can't do the queries separately (putting each type into its own div), then show and hide the divs based on the user input, then that might be a significantly simpler solution to code. That way, you'd be doing simple queries, not trying to bunch them all together and remove the pages).

  • thanks, Jon. i have to say stay within the code as written. i figured this out. $$foliocatlist = get_post_type( $post->ID ) and $entrycategory = get_post_type( $post->ID ); – user1569898 Aug 4 '12 at 10:14
  • Glad you got it! – Jon Schroeder Aug 4 '12 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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