1
votes

I am using the CPT UI plugin which i have created a custom post type with (called Knowledgebase and the taxonomy called knowledgebase-categories)

i am using this code to display posts:

<?php $query = new WP_Query( array('post_type' => 'knowledgebase', 'posts_per_page' => 20, 'category_name' => 'Cisco' ) ); ?>
        <?php while ( $query->have_posts() ) : $query->the_post(); ?>
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <a href=""><?php the_title(); ?></a>
            </article> <!-- .et_pb_post -->
        <?php endwhile; ?>

it works fine without the category_name but with the above code its not showing any posts

there are posts with a category of Cisco

3
use tax_query for the taxonomiesMehar
see my answer below - i worked it outcharlie

3 Answers

1
votes

May this will Help you

<?php $query = new WP_Query( array( 
        'post_type' => 'knowledgebase', 
        'cat' => 5, // Whatever the category ID is for your aerial category
        'posts_per_page' => 10,
        'orderby' => 'date', // Purely optional - just for some ordering
        'order' => 'DESC' // Ditto
    ) );

    while ( $loop->have_posts() ) : $loop->the_post(); ?>
0
votes

Here you can achieve by this

$args = array(
    'post_type' => 'knowledgebase',
    'tax_query' => array(
        array(
            'taxonomy' => 'knowledgebase-categories',
            'field'    => 'slug',
            'terms'    => 'knowledgebase-terms',
        ),
    ),
);
$query = new WP_Query( $args );
0
votes

because they are posts from a custom post type i had to change category_name to the taxonomy (which is knowledgebase-categories)