Home Forums General Issues get_field return empty implementing API


get_field return empty implementing API

  • I created a new taxonomy “quote_category” and added 2 customs fields “category_image” and “category_color”.

    trying to fetch and return these values inside my REST API but only get null.

    “id”: 12,
    “name”: “Fulfillment”,
    “description”: “”,
    “image”: null,
    “color”: null


    function wl_quotecategory() {
    	$terms = get_terms( array(
        'taxonomy' => 'quote_category',
        'hide_empty' => false,
        'fields' => 'all',
    ) );
    	$data = [];
    	$i = 0;
    	foreach($terms as $term) {
    	    // get the current taxonomy term
    	    $image = get_field('category_image', $term->term_id);
    		$data[$i]['id'] = $term->term_id;
    		$data[$i]['name'] = $term->name;
    		$data[$i]['description'] = sanitize_text_field($term->description);
    		$data[$i]['image'] = the_field('category_image', $term->term_id);
    		$data[$i]['color'] = the_field('category_color', $term->term_id);
    	return $data;
  • I’m creating a post via the REST API. On the frontend, get_field_object() returns empty until I go into wp-admin and save a value for an ACF field …

  • it works for me with the POST type, I’m having problems with TEMRS.

    yes, my term object `{
    “id”: 12,
    “name”: “Fulfillment”,
    “description”: “”,
    “image”: null,
    “color”: null

    has an image and color value assigned from the wp-admin

    any idea to solve?

  • made it work using this code instead

    		$cat_lookup_key = 'quote_category_'.$term->term_id;
    		$data[$i]['image'] = get_field('category_image', $cat_lookup_key);
    		$data[$i]['color'] = get_field('category_color', $cat_lookup_key);
    		$data[$i]['priority'] = get_field('category_priority', $cat_lookup_key);

    hope it helps someone else.

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

You must be logged in to reply to this topic.