Home Forums Front-end Issues How to retrieve for a post the taxonomities additional field?


How to retrieve for a post the taxonomities additional field?

  • For some posts I don’t wanna have the title displayed. Instead of managing it via the posts itself I want the option associated with a category. I defined a field ‘hide_title’ which is set for each category with Yes/No.

    When I get a post I have $post_id. So, my q is what is the ‘easiest’ way to solve the relation

    $post_id => category => hide_title

    I would have expected that get_the_terms( get_the_ID(), ‘category’); according to the sample should work. But somehow this remains empty.

    Any hints?

  • wp_get_post_terms() to get the post categories. This will return an array and it will contain multiple categories if the post is in multiple categories, so you’ll need some way of deciding what category to use unless you make sure that only one is ever selected. Once you have the category

    $hide_title = get_field('hide_title', $category->taxonomy.'_'.$category->term_id);
  • Thx for the quick response. First of all the technical hints helped tremendously cause I’m a noob for wp and therefore ….

    and second thx for pointing out that there might be some conflicts when I need to decide which field to take into account.

    and last but not least I recognize that in the category view the additional field will be displayed – but at the very ending – after some time. I’m aware that there is the field but, e.g. pressing on the button ‘update’ in categories the content is displayed quickly and the fields after approx 5-10 sec later. I would assume they are missing – if I don’t know better….

    anyway thx for your awesome help.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘How to retrieve for a post the taxonomities additional field?’ is closed to new replies.