• Resolved mairashraf

    (@mairashraf)


    I have created a custom post type as portfolio_posts using CPT UI plugin. Using the same plugin, i have created a taxonomy named as portfolio_category. I have made multiple entries under this taxonomy. Now i want to list all the entries under portfolio_category and i am doing this in my code
    <br />

    $args = array(<br />
            'taxonomy' => 'portfolio_category'<br />
          );<br />
        $taxonomy = get_categories ($args);<br />
        echo '<br />
    <pre>';
        print_r($taxonomy);
        exit;
    </pre><code></code>


    but it return an empty array. when i replace portfolio_category with category i am successfully getting all the entries under category. What am i missing here?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mairashraf

    (@mairashraf)

    Here is how i did it, after lots browsing found the solution on wordpress support forum
    $tax_terms = get_terms(‘portfolio_category’, array( ‘hide_empty’ => 0 ));

    Clarion Technologies

    (@clarionwpdeveloper)

    Hi,

    Try the following code and see if it works for you.

    $args = array('post_type' => 'custom_post_type',
            'tax_query' => array(
                array(
                    'taxonomy' => 'custom_taxonomy',
                    'field' => 'slug',
                    'terms' => $custom_term->slug,
                ),
            ),
         );
    
         $loop = new WP_Query($args);
         if($loop->have_posts()) {
            echo '<h2>'.$custom_term->name.'</h2>';
    
            while($loop->have_posts()) : $loop->the_post();
                echo '<a href="'.get_permalink().'">'.get_the_title().'</a>';
            endwhile;
         }

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom Post Type Taxonomy’ is closed to new replies.