Home Forums General Issues Get a CPTs Taxonomy from Post Object


Get a CPTs Taxonomy from Post Object

  • This might well be the most stupid question on the month, but I’ve been trying for hours and don’t get anywhere, so here goes…
    I have a site with two Custom Post Types that each have one Taxonomy with only a single Term attached:
    Members –> Departement
    Events –> Type of Event

    Inside Events, I have a Post Object relational field, where I can select one of the Members as Speaker at an event.

    Now what I’m desperately trying to get is this Members Department name, i.e. the Custom Post Type’s Taxonomy or Category. I can get the other fields easily:

    $post_object = get_field( 'event_member_speaker' );
    				if( $post_object ) {
    					$post = $post_object;
    					setup_postdata( $post );				
    					$firstName = get_field( 'first_name' );
    					$lastName = get_field( 'last_name' );

    But the Taxonomy term always returns empty, whatever I try.

    Before using ACF, I got the term via

    $dept = wp_get_object_terms( $id, 'department' );
    		$dept = $dept[0];

    so I’m pretty sure there must be a (probably really simple) way to cajole ACF to show this too, but obviously I’m too thick to see it.

  • Setting the Relational Post Object to write back to the post (the german translation for this function is not entirely cleat BTW), changing the taxonomy selector to Radio Button (drop down seem to have a bug, as it mixes taxonomies translations) and opening and re-saving every member CPT did the trick, with the following code:

    $tax = get_field_object("department");
    $taxnum = $tax['value'];
    $taxtax = $tax['name'];
    $dept = get_term( $taxnum, $taxtax );
    $deptname = $dept->name;

    Now for the same fun in a repeating field group… yay!

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

You must be logged in to reply to this topic.