skip to Main Content

I’m currently trying to print a value from a sub field. I have the reapeater "faixas" that has the sub fields: "nome", "interprete" and "letra". On the custom fields area, I have the field "upc" that I print easily using echo('"'.get_field('upc').'";');, but when I try to do the same with "nome, interprete and letra", they just don’t print. I already tried to print using echo('"'.get_sub_field('nome').'";');, but it didn’t worked. I don’t know if I need to point the sub field for the faixas repeater, can please someone help me?

2

Answers


  1. Chosen as BEST ANSWER

    Looking for it I've found this solution:

    if(have_rows('faixas')):
                     while(have_rows('faixas')) : the_row();
                     $letra = get_sub_field('letra');
                     echo $letra;
                     $nome = get_sub_field('nome');
                     echo ' ; '.$PHP_EOL.$nome;
             endwhile;
    endif;
    

  2. For this answer I’m assuming you’re using ACF to store that repeater.
    If that is the case, this should do the trick:

    $faixas = get_field('faixas');
    
    foreach ($faixa in $faixas) {
        echo('"'.$faixa['nome'].'";');
        echo('"'.$faixa['interprete'].'";');
        echo('"'.$faixa['letra'].'";');
    }
    

    When getting a repeater, you receive an array of the rows inside it (which I store in $faixas in this example).
    In turn, each row is an associative array where the keys are the subfields’ names.

    Hope this helps, keep on coding!

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