从REST API的分类术语中获取ACF转发器字段

时间:2020-05-24 02:28:11

标签: wordpress api advanced-custom-fields taxonomy wordpress-rest-api

当我从分类学中获得图像字段时,它就可以正常工作

但中继器字段数据显示null

// /wp-json/wp/v2/taxonomy-reviews/taxonomyName
function taxonomyReviews($taxonomyName) {
    $terms = get_terms([
        'taxonomy' => $taxonomyName['name'],
        'hide_empty' => false,
    ]);

    $reviews = [];
    foreach ($terms as $term) {
        $reviews[]=[
            'name' => $term->name,
            'slug' => $term->slug,
            'image' => get_field('image', $taxonomyName['name'] . '_' . $term->term_id),
            'reviews' => get_field('weds_reviews', $taxonomyName['name'] . '_' . $term->term_id),
        ];
    }
    return $reviews;
}
[
    {
        "name": "Bridal Designers",
        "slug": "bridal-designers",
        "image": "http://wedsphotography.local/wp-content/uploads/2020/04/Rectangle-952-7.png",
        "reviews": null
    },
    {
        "name": "Bridal Makeup Artist",
        "slug": "bridal-makeup-artist",
        "image": "http://wedsphotography.local/wp-content/uploads/2020/04/Rectangle-952-2.png",
        "reviews": null
    }
]

0 个答案:

没有答案