It sounds like you’re trying to get the category terms for a post. Category terms are not stored in post meta.
You can get a post’s terms using get_the_terms()
. In this example, $terms
will hold an array of term objects for the category
taxonomy associated with the current post. You can replace category
with your custom taxonomy name.
$terms = get_the_terms( get_the_ID(), 'category' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<ul>';
foreach ( $terms as $term ) {
echo '<li>' . $term->name . '</li>';
}
echo '</ul>';
}
Each term object will look like this as we iterate over the foreach loop in the above code:
WP_Term Object
(
[term_id] => 2
[name] => Alignment
[slug] => alignment
[term_group] => 0
[term_taxonomy_id] => 2
[taxonomy] => category
Get Meta Keys of Custom Categories => Posts in this category test image and text alignment.
[parent] => 0
[count] => 4
[filter] => raw
)