Support

Account

Home Forums Add-ons Flexible Content Field fixable content fields value json api

Solving

fixable content fields value json api

  • Hello , I am using this code to get return value for ACF in a custom post type , but I cant seems to get the fixable content fields value

    please help to update this code to add the flexible content

    function wl_sportteams() {
        $args = array(
                'numberposts' => 99999,
                'post_type' =>  'sport_teams', 
                'orderby'       => 'menu_order',
                'order'         => 'ASC',
                'suppress_filters' => false
                
                );
    
        $posts = get_posts($args);
    
        $data = [];
        $i = 0;
    
        foreach($posts as $post) {
            $data[$i]['id'] = $post->ID;
            $data[$i]['Team_Name'] = get_field('sport_team_name', $post->ID);
            
            
            
            $i++;
        }
    
        return $data;
    }

    What to add here to get the flexible fields values please

    thanks

  • is “sport_team_name” the name of the flex field or is this the name of one of the sub fields in a layout?

  • Hello
    The group start like this :

    Group name : Team Names

    Fields :

    Label : Teams | Name : Teams | type : Flexible content

    then

    Layout

    Name : Team info | Label : team_info | Type Block

    then

    Fields

    Label : Sport Team Name | name : sport_team_name | type : text

    I hope this is clear , if not i can send you a screen shot , so basically the sport_team_name is ” a field inside a block inside flexible content ”

    Thank you for you help..

  • so I Guess it is name of one of the sub fields in a layout

  • You need to loop over the layouts in the flex field to get the sub field values. See example code here https://www.advancedcustomfields.com/resources/flexible-content/

  • yes i Have seen this , and thank you for the reply , but I have no idea how to implement it in the above script i sent , i hope you can guide me , ot edit my script just to see some example if possible thanks you

  • Any chance to get a solution please

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

You must be logged in to reply to this topic.