php - show custom fields data in next and previous link in wordpress
I am trying to show a advanced custom fields data in previous post link in wordpress. But The data is not showing also it breaks the html as well.
<div >
<?php
$prev_post = get_previous_post();
if($prev_post) {
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '" >
<strong>
<<< "'. $prev_title . '"
</strong>
<img src="'.the_field("girl_image").'" alt="'.the_title().'/>
</a>' . "\n";
}
?>
</div>
In this code the "girl_img" field contains the URL of an image. I want to show the image based on the URL. But it is showing the URL itself instead of showing the image.
Answer
Solution:
Use
get_field()
instead ofthe_field()
.get_field()
= Returns the value of the specified field.the_field()
= Displays the value of the specified field. This function is the same asecho get_field($field_name)
;Replace
the_field("girl_image")
withget_field("girl_image")