Forums Get help. Give help.

Wordpress 3.1 | Display Custom Post Types data BY Custom Taxonomy
  • Hi!

    I'm new to PHP and Wordpress 3.1 Custom Post Types and Taxonomies. I've created the title so others can easily find this solution later.

    For a client, I have made my own custom post types with their own custom taxonomies in functions.php.

    Now I want to use the single.php to grab the Custom Field $key by $value, if it exists. If that $value is "youth", I want to pass that value into a function that will query my site for the custom taxonomy that I made and if it finds data, it will show that data. The data that's in the custom post type. I want to display that custom post type's excerpt() and title().

    This is an author's site. The single.php displays a book and information related to it. At the bottom, I want to pull in reviews based on which custom taxonomy they are a part of (these taxonomies are tied to the custom post types). So if the book is about youths, I want to pull my reviews organized by the custom taxonomy, youths.

    I feel I've tried all that I could find to implement, but I haven't gotten over the learning curve enough to understand why it doesn't work, so I'm not able to fix it.

    Thank you so much for your help.
    Daniel
  • Well, several hours later, I solved my own problem. Place this code outside the main loop.

    <!-- Pull Custom Posts based on the Custom Taxonomy  from Custom Field-->
    <?php if ($value = get_post_meta($post->ID, $key, true) ); { ?>
    <?php $args = array( 'parent-custom-taxonomy' => 'child-custom-taxonomy', 'showposts' => 3 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <div class="review">
    <h4>Latest Reviews</h4>
    <?php the_content();?>
    <span>&#8212;<?php the_title(); ?></span> <!-- em dash at beginning of title/name of person -->
    <?php echo '</div>';
    endwhile; ?>
    </div><!-- eof review -->
    <?php }; ?>





Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

Tips

Just some helpful hints to get the most out of the forums.