Support

Account

Home Forums General Issues Issue with Displaying Labels Instead of Values for ACF Dynamically Populated Sel Reply To: Issue with Displaying Labels Instead of Values for ACF Dynamically Populated Sel

  • @hube2
    Thank you for your prompt response.

    screen shot
    This is a screenshot of the ACF select field settings (note that it includes Japanese text). The choices for this select field are automatically updated when a separate textarea is modified.

    As mentioned in my initial post, I am following the instructions provided here: ACF Guide on Dynamically Populating Select Fields.

    Regarding the code used for display, it is executed via the WordPress REST API. Below is a simplified version of the code. Please note that it may look odd due to simplification, but essentially, it’s just using get_field to retrieve data. Since the select field works correctly with choices that were initially present and after performing an export/import, I believe there is no bug in this code.

    
    <?php
    add_action('rest_api_init', function () {
        register_rest_route(
            'v1',
            'matches/(?P<slug>[a-z0-9_\-]+)',
            array('callback' => 'matchesResponse')
        );
    });
    
    function matchesResponse($request)
    {
        $post_args = [
            'name'              => $param_slug,
            'post_type'         => 'matches',
            'post_status'       => $request['post_status'],
            'posts_per_page'    => -1
        ];
    
        $post_query = new WP_Query($post_args);
    
        if ($post_query->have_posts()) :
    
            while ($post_query->have_posts()) :
    
                $post_query->the_post();
    
                global $post;
    
                $data[] = get_field('opponent', $post->ID);
    
            endwhile;
    
            wp_reset_postdata();
        endif;
    
        print_r($data);
    
        return new WP_REST_Response($data);
    }