0
votes

I have Portfolio custom post type with category. I would like to use a template to get Portfolio Posts by Only one category.

$args = array( 
     'post_type' => 'portfolio',
     'posts_per_page' => -1,
     'category_name' => 'casino'
  );

If I use category_name with a category slug like 'casino', I have to create templates for every category, but I don't want it. I want to use only one template & the category slug will be placed dynamically on the category_name value. How can I create it?

1

1 Answers

0
votes

To create a category template for a custom post: get the category object using;

<?php $term = get_queried_object(); ?>

you can then echo this, as a page title, so that your users will know they are browsing a certain category, then using it in the custom query parameters.

<?php echo $term->name; ?> // shows category name

    $args = array(
        'post_type' => 'portfolio',
        'category_name' => $term->slug
        );