I want to link content comprised of a custom field(field1_details) using another custom field(field2_link) which is a URL type. the_field('field1_details')
is text_area field and get_field('field2_link')
is a website field (using a ACF addon).
(These custom fields are created using Advanced custom fields plugin)
Here is the code I am trying in loop.php:
<span class="c_f"><a href="<?php get_field('field2_link'); ?>"><?php if( function_exists('the_field') ) the_field('field1_details'); ?></a></span>
Output-
<a href="">The text content</a> ( Doesn't out put the link)
And tried this without the if
<span class="c_f"><a href="<?php get_field('field2_link'); ?>"><?php the_field('field1_details'); ?></a></span>
Trying with the_field
instead of get_field
<span class="c_f"><a href="<?php the_field('field2_link'); ?>"><?php the_field('field1_details'); ?></a></span>
Output-
<span><a href="<a href=" http:="" google.com"="" target="_blank">google.com</a>">This is the test content</span>
=====================================================
The two custom fields works fine if I use them separately like this:
Field 1- field1_details
Output HTML-
<div class="field-wrap"><span class="field icon-edit">This is the Text
content</span></div>
Field 2- field2_link
or without the if
<span class="link-field"><?php the_field('field2_link'); ?></span>
Out put-
<span class="link-field"><a href="http://google.com"
target="_blank">google.com</a></span>
I think I am not using it in a right way. Could any one tell me how to link the field with a URL entered in the another field in loop.php?
Also tell me how would you do it in the functions.php instead of the templates like loop.php