Reputation: 481
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
Upvotes: 1
Views: 1291
Reputation: 506
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(); ?>
Upvotes: 1
Reputation: 481
because they are posts from a custom post type i had to change category_name
to the taxonomy (which is knowledgebase-categories)
Upvotes: 0
Reputation: 2228
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 );
Upvotes: 0