• Resolved raajen

    (@raajen)


    Hello,
    I am having a problem with custom post type and custom taxonomies. I created a custom post type called ‘galleries’ and taxonomies named ‘gallery_type’. And I have created a page called Gallery in which i loaded all the posts from galleries. And then I have created ‘garden’ & ‘house’ taxonomy terms and assigned 3-3 posts to each ‘garden’ & ‘house’. And I linked the taxonomy terms ‘garden’ and ‘house’ as sub-menu to gallery which is my current parent. I want to display the posts in their respective terms. But it is not loading. What can I do ??
    My code is: `
    $tax = ‘gallery_type’;
    $terms = get_the_terms($post->ID, $tax);
    if($terms){
    foreach($terms as $term){
    $single = $term->name;
    ?>

    <ul>
    <?php
    $args = array(‘post_type’=>’galleries’,
    ‘posts_per_page’=> -1,
    ‘tax_query’=>array(
    array(‘taxonomy’=>’gallery_type’,
    ‘terms’=> $single)
    ),
    ‘order_by’=>’post_date’);
    $query = new WP_Query($args);
    if($query->have_posts()){
    while($query->have_posts()):
    $query->the_post();
    $post_id = $post->ID;
    ?>
    <li class=”thumb <?php echo $post_id; ?>” onclick=”changeContent(<?php echo $post_id; ?>);”>
    <?php if(has_post_thumbnail())
    the_post_thumbnail(‘gallery-thumb’);
    ?>

    <?php
    endwhile;
    wp_reset_query();
    }
    else{
    _e(‘No image found in gallery’,’bseep’);
    }
    `

    Any fix???

Viewing 3 replies - 1 through 3 (of 3 total)
  • Tracy Levesque

    (@liljimmi)

    🏳️‍🌈 YIKES, Inc. Co-Owner

    Hi there. You can use the Template Hierarchy to create templates for those 2 custom taxonomies and just style them as you like.

    You wont have to call up the taxonomy in your query if you name the files correctly.

    If you follow the Template Hierarchy chart, you can name your template.
    taxonomy-gallery_type.php and it will apply to both “garden” and “House” If you want to make a different template for each you can name them taxonomy-gallery_type-garden.php and taxonomy-gallery_type-house.php

    Then you can just link to those archive pages in your menu.

    Thread Starter raajen

    (@raajen)

    Solved Myself.. hurray .. got the crap out of my head ….. 😀

    Thread Starter raajen

    (@raajen)

    Tracy i used the same template hierarchy.. But the contents were not loading.. Actually the tags were not being queried so my head was spinning around it…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Taxonomy and Custom Post Types’ is closed to new replies.