Support

Account

Home Forums Front-end Issues Data from the_field doesnt show up on the right place

Solved

Data from the_field doesnt show up on the right place

  • Hey guys,

    I have a problem with the output of the content from “the_field()” fields. The following is my code:

    $review_recaps_class = get_post_class();
    				if ((in_array("genre-filme-reviews", $review_recaps_class)) OR (in_array("genre-filme-recaps", $review_recaps_class))) {
    					$ouput .='<div>'.the_terms( $post->ID, 'regisseur', 'Regisseur: <span class="flight">', ', ', '</span> ' )
    					.'• Erscheinungsdatum:<span>'
    					.the_field('produziert')
    					.'</span>• FSK: <span>'
    					.the_field('fsk')
    					.'</span>• Filmlänge: <span>'
    					.the_field('filmlaenge')
    					.'</span>• Schauspieler:'
    					.the_terms( $post->ID, 'schauspieler', 'Besetzung: <span class="flight">', ', ', '</span> ' ).'</div>';
    				} elseif ((in_array("genre-serien-reviews", $review_recaps_class)) OR (in_array("genre-serien-recaps", $review_recaps_class))){
    					$ouput .='<div>'.the_terms( $post->ID, 'regisseur', 'Showrunner: <span class="flight">', ', ', '</span> ' )
    					.'• Staffelstart: '
    					.the_field('produziert')
    					.'• FSK: '
    					.the_field('fsk')
    					.'• Episoden: '
    					.the_field('episoden')
    					.'• Schauspieler:'
    					.the_terms( $post->ID, 'schauspieler', 'Besetzung: <span class="flight">', ', ', '</span> ' ).'</div>';
    				}

    On this picture you can see the the content of the fields are only show up in the source code (not on the page) and also on the wrong place:

    The content should normally be show up on this place between the <span>-tags:

    What is wrong? Can you help me? :/

  • the_field() echos the value where it appears in the code. To get the value you need to use get_field(). Example; $output = 'something and.get_field();`

    You will find that ‘the_terms()` works the same way.

  • The problem is not to get the values – it works which you can see in the screenshots. But for some reason the values are on the wrong place. Thats my problem :/

  • Yes, it is. Sorry, but you are using the wrong function. The values are in the wrong place because they are echoed at the point where the function the_feild() is called.

    Example:

    
    // this will output the value of a field here
    // and set $value == NULL
    // because the_field() does not return a value
    $value = '<p>The value of the field is echoed here ('.the_field().')</p>';
    
    // this will echo the <p> with nothing in the ()
    // because the_field() already echoed the value above 
    // and returned NULL
    echo $value
    
    

    I won’t go into the issues with using ‘the_terms()’ in the context that you are attempting to use it. Removing that from one of your lines what it should look like is this

    
    $ouput .='<div>'
    .'• Erscheinungsdatum:<span>'
    .get__field('produziert')
    .'</span>• FSK: <span>'
    .get__field('fsk')
    .'</span>• Filmlänge: <span>'
    .get__field('filmlaenge')
    .'</span>• Schauspieler:'
    .'</div>';
    
    echo $output;
    
    


    the_field()

    get_field()

  • Ok, the fields where I work with get_field() I now get in the right place. But the fields where I currently still try to get the result with the_terms() do not work.

    I tried the_terms() because more than one result can come out.

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

You must be logged in to reply to this topic.