Taxonomies

Our custom post type also contains the custom taxonomies for better organizing your projects:

  • Category (slug portfolio_category)
  • Tag (slug portfolio_tag)

There are a couple of ways to display these taxonomies on your site using Block Editor or PHP.

Taxonomies used in Project (Block Editor)

There is a block named Portfolio Categories, which you can insert in Project pages:

The similar block you can find for displaying post tags, which is named Portfolio Tags:

Taxonomies used in Project (PHP)

There is a function named wp_get_post_terms, which you can use in project templates to display the list of categories and tags of the current portfolio post. Usage example:

// Get the portfolio categories list used in the selected portfolio project.
$categories_list = wp_get_post_terms( get_the_ID(), 'portfolio_category' );
var_dump( $categories_list );


// Get the portfolio tags list used in the selected portfolio project.
$tags_list = wp_get_post_terms( get_the_ID(), 'portfolio_tag' );
var_dump( $tags_list );

You can find more functions to work with the selected post taxonomies. Look at the list with some similar functions:

Full list of Portfolio taxonomies (Block Editor)

To display the list of all available Portfolio Categories or Portfolio Tags, you can use the Tag Cloud block and select the needed Taxonomy in the block settings:

Full list of Portfolio taxonomies (PHP)

There is a function named get_terms, which you can use in PHP templates to display the list of all portfolio categories and tags. Usage example:

// Get the full portfolio categories list.
$categories_list = get_terms(
    array(
        'taxonomy'   => 'portfolio_category',
        'hide_empty' => false,
    )
);
var_dump( $categories_list );


// Get the full portfolio tags list.
$tags_list = get_terms(
    array(
        'taxonomy'   => 'portfolio_tag',
        'hide_empty' => false,
    )
);
var_dump( $tags_list );
Was this page helpful?