Display text link using Advanced Custom Fields Pro

Hi, I am trying to display a text link using Custom Fields Pro. (I had this set up before, but my modification of the wp-single.php file seems to have been lost during an upgrade, even though it was in the child theme.) The code I have so far successfully displays the two text fields at the bottom of each post, but I can’t figure out how to turn one of the text fields into a link. I want to make the field [image_photographer] link to [photographer_url]. Thanks for your help.

Website: travelstudies.org
Wordpress: 4.9.8
X Theme: 6.2.5
Cornerstone: 3.2.5

Here’s the code I have so far:

<?php // ============================================================================= // VIEWS/ETHOS/WP-SINGLE.PHP // ----------------------------------------------------------------------------- // Single post output for Ethos. // ============================================================================= $fullwidth = get_post_meta( get_the_ID(), '_x_post_layout', true ); get_header(); ?>
    <?php while ( have_posts() ) : the_post(); ?>
      <?php x_get_view( 'ethos', 'content', get_post_format() ); ?>      
      (Image: <?php the_field('image_title') ?>; Source: <?php the_field('image_photographer') ?>)
      
      <?php x_get_view( 'global', '_comments-template' ); ?>
    <?php endwhile; ?>

  </div>

  <?php if ( $fullwidth != 'on' ) : ?>
    <?php get_sidebar(); ?>
  <?php endif; ?>

</div>
<?php get_footer(); ?>

Hi there,

Please double check that you have the wp-single.php in wp-content/themes/x-child/framework/views/ethos.

If the file is already there, please check the field names in the code match the field names you have setup in the admin.

Let us know how it goes.

I’m sorry, I did not explain the issue clearly enough. Two of the fields are appearing correctly in the posts, so I have the wp-single.php file working properly. I am trying to modify the code so that a third field is a link on one of the other fields. I want the image_photographer field to appear in the post (as it does now), but I want this field to be a link that goes to the photographer_url field. It’s just about coding the link properly. This code is currently working:
(Image: <?php the_field('image_title') ?>; Source: <?php the_field('image_photographer') ?>)

I simply want to integrate something like this into the code:
image_photographer

Thanks again.

Hi There,

You can try with this code:

Image: <?php the_field('image_title') ?>; Source: <a href="<?php the_field('photographer_url'); ?>"><?php the_field('image_photographer') ?></a>

Hope it helps :slight_smile:

That worked perfectly! Thank you very much!

You’re most welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.