Home Forums Feedback Directly get a layout by its ID Reply To: Directly get a layout by its ID

  • There are few ways you can do this, the first is not really optimized, but it will shorten the work.

    $flex = get_field('flexible_content_field');

    That will put the entire contents of the flex field into an array and then you can get the row by targeting the array element you need

    // the array elements start with 0 instead of 1
    // so row 2 will be element 1 of the array
    $text = $flex[1]['text_field'];

    You will need to output the contents of the array to be 100% certain what it contains, and it will give you a better idea of what to do with it.

    echo '<pre>'; print_r($flex); echo '</pre>';

    While not 100% optimized, because you are getting all of the rows at once, the values are cached so additional calls to get the entire flex content should not generate additional queries to the DB.

    The second way is to only get what you want using get_post_meta()

    For example, a text field on the second row will have a meta key that looks something like this repeater_field_name_2_text_field_name. The meta key repeater_field_name will return a array of the layouts for each row.

    Like I said, more complicated, but you only get what you need.