I’m currently trying to setup ACF taxonomy field value in my controller. Currently its outputting a number instead of the name. I’ve read through a lot of documentation and tried lots of examples relating to terms but keep coming back to the code posted here. I’d rather not post all the things of tried because it’s trashy. Not sure if I should be esc_html or apply a filter for the ACF taxonomy select or querying taxonomy or terms. In the ACF setup, the options are Term Object and Term ID. Term Object returns an error - Object of class WP_Term could not be converted to string and Term ID returns, well an ID.
I’ve tried following:
My ACF taxonomy field in controller:
'joblocation' => get_field('pj_job_location', $post->ID),
My current Controller code:
namespace App\Controllers;
use Sober\Controller\Controller;
class TemplateJobs extends Controller
{
protected $acf = true;
public static function jobsLoop($postType)
{
$item = get_posts([
'post_type' => $postType,
'posts_per_page' => 50,
]);
return array_map(function ($post) {
return [
'title' => apply_filters('get_the_title', $post->post_title),
'excerpt' => apply_filters('get_the_excerpt', $post->post_excerpt),
'postdate' => get_field('pj_job_post_date', $post->ID),
'jobtype' => get_field('pj_employment_type', $post->ID),
'permalink' => apply_filters('permalink', get_permalink($post)),
'joblocation' => get_field('pj_job_location', $post->ID),
];
}, $item);
}
}
This is simplistic. Within the blade controller post loop:
{!! $item['joblocation'] !!}
This outputs a number. Any guidance/reference would be great. Cheers.