I have 4 different custom entries from my custom category.

Categories are: john-doe, jane-doe, john-does, jane-does

Each of the user have different posts. Let's say John Doe have a post, but on that post, I wanted to display his name via the post, but how can I fetch his category name "John Doe" without using the tax_query?

For example: John Doe have a post (same with his custom category name) and the url is, "www.domain.com/john-doe" he have a post here and the url is, "www.domain.com/portfolio/name-of-the-post. This post have all the contents except the category. So by that, How would I know if the post custom category was from John Doe without declaring or using the code below?

I tried get_the_category(), get_category() but throws error.

PS. I use this code and it was working fine to display all posts under their names manually.

$my_query = new WP_Query( array(
            'terms'=>'john-doe'  // change to real slug
) );

while ( $my_query->have_posts() ) {
    // display post

1 Answer 1


I found the answer CSS Tricks and it works.

Here's the code I use.

$terms = get_the_terms( $post->ID , 'portfolio_user' );
foreach ( $terms as $term ) {
  echo $term->slug;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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