Display the category posted in post type in wordpress

Asked

Viewed 1,223 times

0

How do I display the category registered in a post type in Wordpress?

I’m using the Odin Framework, I created a post type called products and would like to display the category next to the post.

Ex: Posted on July 6, 2017 in the category Refrigerators.

In blog posts, to display the categories the following code is used:

<?php echo __( 'Posted in:', 'odin' ) . ' ' . get_the_category_list(); ?>

inserir a descrição da imagem aqui

1 answer

1

I’m not sure how your framework works, but using some WP functions can do this in various ways:

$categoria = get_category(get_query_var('cat'))->name;

Ref:


$categoria = get_cat_name( $cat_id );

Ref:


Anything take a look at this link, deals with a case similar to yours.

  • I found a possible solution, but now it is displaying categories that the product does not belong. Ex: Ex: I have two products, refrigerator and stove, the refrigerator category has several subcategories, so mark all of them and the television category has only one. When I access the television product, it lists the category of refrigerators as well, why does this happen? Category: Refrigerator, small, television... Code used: http://pastebin.com/8e4d7Bn8

Browser other questions tagged

You are not signed in. Login or sign up in order to post.