Grow your CSS skills. Land your dream job.

WordPress 3.1 | Display Custom Post Types data BY Custom Taxonomy

  • # March 9, 2011 at 10:33 am

    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

    # March 9, 2011 at 6:40 pm

    Well, several hours later, I solved my own problem. Place this code outside the main loop.


    < ?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(); ?>


    Latest Reviews


    < ?php the_content();?>
    —< ?php the_title(); ?>
    < ?php echo '
    ';
    endwhile; ?>

    < ?php }; ?>
# September 10, 2013 at 2:01 am

Hi danielbrinneman

Actually am looking for something close to what you have just said. Am new to wordpress and am making a wordpress which involves products. I have created a custom post type for the products and added 3 custom taxonomies to the product post type. My aim is to have a product to belong to product_category,product_brand and product_type. Then I would like to have a query which will return the products with their respective category, brand and type. Is that really possible? If so I will really appreciate your help. Here is my functions file (http://codepad.org/opDNhZPf)

Thanking you in advance as am waiting to hear from you

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".