0

I`ve created a custom post type with categories. How can I get the URL to display only posts from a specyfic category of that custom post type?

2
  • 2
    Please add some more information. What do you mean by "the URL"? What have you tried?
    – DeltaG
    Jan 5 at 14:13
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Jan 13 at 13:30

1 Answer 1

0

I'm not sure if you are looking for a Taxonomy query... or a way to get terms, does one of these solutions answer your question. Please don't downvote as I am going of very limited information and guessing here at what you need.

<?php
  $args = array(
    'post_type' => 'post-type',
    'posts_per_page' => 5,
    'tax_query' => array(
      array(
        'taxonomy' => 'taxname_tax',
        'field' => 'slug',
        'terms' => 'term-to-query'
        )
      )
    );
  $listing_query = new WP_Query($args);
?>

<?php if ( $listing_query->have_posts() ) : while ( $listing_query->have_posts() ) : $listing_query->the_post(); ?>

  <?php the_title(); ?>

<?php endwhile; endif; // end of taxonomy query loop. ?>
<?php wp_reset_postdata(); ?>



// or a taxonomy lookup
<?php $terms = get_the_terms( $post->ID, 'taxonamy_tax' ); ?>
<?php foreach( $terms as $term ) echo $term->slug; ?>
 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.