Reputation: 399
I've got an issue. I've created a custom field via ACF wordpress plugin. Its a field to custom post type categories (lets say its an additional description to the category). I've tried to add it to my page via such code:
$return_html.= '<h2 class="ppb_menu_title" ';
$return_html.= '>'.$menu_term->name.'</h2><br class="clear"/><br/>';
$displaytitle = the_field('category_subtitle');
$return_html.= '<div class="subtitledesc">'.$displaytitle.'</div>';
below code is a part of full page of code which you can find here [lines 1712-1715]: https://codeshare.io/50QzqL
what i am doing wrong?
Upvotes: 1
Views: 866
Reputation: 423
You'll want to use get_field()
instead of the_field()
and include the term ID.
get_field()
returns a value.
the_field()
echoes a value.
Try this: get_field('category_subtitle', 'term_' . $menu_term->term_id)
Upvotes: 0
Reputation: 2982
get_field() with a single parameter only works on the current post within the loop iirc, so you will have to provide a target if you're trying to get data for a category.
You'll need the termid of your category (when you're on a taxonomy-page, $term = get_queried_object(); $termid = $term->term_id;
should work), then use get_field like so:
get_field( 'category_subtitle', "taxonomyname_$termid" );
get_field( 'category_subtitle', $term ); // if you have a term object
Further reading: https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/
Upvotes: 1