skip to Main Content

I’ve a concern about the use of subfields in ACF. I wish there was a way to display them in an easy way without using loops.

Let’s pose the case of this flexible field structure named ‘Content’:

- paragraph
- - title
- - text

I would like to be able to display, via shortcode or something like that, a specific subfield via its parent field’s index number, e.g:

<?php echo the_flexible_field('content') > the_field('paragraph_3') > the_subfield('title'); ?>

In the example above I intend to display (ONLY) the title of the third paragraph.

I can’t find anything about this in the documentation, I guess this possibility probably doesn’t exist completely however I’ll try to ask here anyway, just in case.

Thanks

2

Answers


  1. There is no way to return the subfield values from the flexible content outside the look.

    It is worth mentioning that the the_flexible_field() function is deprecated as of ACF 3.3.4 and ACF recommends using the have_rows() function instead.

    Login or Signup to reply.
  2. You can get the field using

    $field = get_field('content');
    

    This will give you an array of the field rows, you can then loop through or echo whatever you like out of it. I’m assuming your field is set up like the screenshot below.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search