Home Forums Front-end Issues Custom field not showing on page – title displays fine


Custom field not showing on page – title displays fine

  • I’ve created a custom field and a post that uses that custom field. I’m trying to display it on a page like this:

    $args = array( 'post_type' => 'Portfolio Item' );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    	echo '<p>' . the_title() . '</p>';
    	echo '<a href="#">' . the_field('portfolio_url') . '</a>';

    The title displays no problem, but the custom field does not (i.e. the output is just <a href="#"></a>). The name ‘portfolio_url’ is the ‘Field Name’.

    Can anyone help with what I’m doing wrong?

  • Hi!

    You should use the post types slug for the post_type argument.. which I’m guessing would be portfolio-item?

    The reason why your ACF field is not being displayed is because you’re using the_field which tries to echo the result itself. In this case you’re already doing that so replace the_field with get_field and you should be golden!

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.