Support

Account

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

Helping

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:

    <?php
    $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>';
    endwhile;
    ?>

    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)

The topic ‘Custom field not showing on page – title displays fine’ is closed to new replies.