WordPress.org

Ready to get started?Download WordPress

Forums

Display List of Custom Post, taxonomy & terms (1 post)

  1. pratikc
    Member
    Posted 1 year ago #

    I used following code to display custom post & taxonomy, but its not display terms under its parent.
    My Custom Post: Product
    Taxonomy: producttype

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    <h1>Categories</h1>
                    <?php
                    $terms = get_terms('producttype');
                        foreach ($terms as $term)
                        {
                            $wpq = array ('taxonomy'=>'producttype','term'=>$term->slug);
                            $myquery = new WP_Query ($wpq);
                            $article_count = $myquery->post_count;
                            echo "<h3>";
                            	echo '<a href="'.get_term_link($term, $taxonomy).'">'.$term->name.'</a>';
                            echo "</h3>";
                            if ($article_count)
                            {
                                echo "
    <ul>";
                                while ($myquery->have_posts()) : $myquery->the_post();
                                echo "
    <li><a>".$post->post_title."</a></li>
    ";
                                endwhile;
                                echo "</ul>
    ";
                            }
                        }
                    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic