T
T
Toster7772018-03-25 15:32:07
WordPress
Toster777, 2018-03-25 15:32:07

How to display custom post type with categories?

There is a code that displays a custom post type:

<?php
$args=array(
'post_type' => 'products',
);

$products = get_posts($args);
foreach ($products as $post) :
setup_postdata($post);
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endforeach; ?>

How to make it so that it displays not all posts, but posts of a certain category by ID?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
E, 2018-03-25
@Toster777

$args = array(
  'post_type'            => 'products',
  'taxonomy_name' => 'category_name'
);
$query = new WP_Query( $args );

this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question