Support

Account

Home Forums Front-end Issues Can't get the_field value to show up in the front-end

Helping

Can't get the_field value to show up in the front-end

  • I have been struggling with getting the value of a field to show up on the front end for some time now. Finally at wits end.

    I am currently using X theme. Within X theme I am using The Grid plugin from Themeone. To site currently being worked on is http://f04.300.myftpupload.com/.

    Here is the code being used:

    $output .= $tg_el->get_content_wrapper_start();
    		$output .= $tg_el->get_the_terms($terms_args);
    		$output .= '<div class="artist_name"> Poster Name Should Display Here -->' . the_field('poster_name') . '</div>';
    		$output .= '<div class="artist_name"> Artist Name Should Display Here -->' . the_field('artist_name') . '</div>';
    		$output .= $tg_el->get_the_title();
    		$output .= $tg_el->get_the_excerpt($excerpt_args);
    		$output .= $tg_el->get_read_more_button($readmore_args);
    		$output .= '<div class="tg-item-footer">';
    			$output .= $tg_el->get_the_date();
    			$output .= ($comments) ? '<span>/</span>' : null;
    			$output .= $comments;
    		$output .= '</div>';
    	$output .= $tg_el->get_content_wrapper_end();

    The specific two lines of code I am working with are:

    $output .= '<div class="artist_name"> Poster Name Should Display Here -->' . the_field('poster_name') . '</div>';
    		$output .= '<div class="artist_name"> Artist Name Should Display Here -->' . the_field('artist_name') . '</div>';

    I’ve also tried this:

    $output .= '<div class="artist_name"> Poster Name Should Display Here -->' . the_field('poster_name', get_option('page_for_posts')) . '</div>';
    		$output .= '<div class="artist_name"> Artist Name Should Display Here -->' . the_field('artist_name', get_option('page_for_posts')) . '</div>';

    In both examples I’ve added a bit of straight HTML to identify where it should be displaying. All that said, I still cannot get the value of these fields to display. Any help is greatly appreciated. Thanks a ton.

  • Hi @joshcoledesign

    The the_field() function will echo the value when you use it. If you want to pass the value to a variable, please use the get_field() function instead. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/displaying-custom-field-values-in-your-theme/.

    I hope this helps 🙂

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

You must be logged in to reply to this topic.