0

I created a custom ACF Field called 'url' under the user registration data section which will carry the facebook homepage of the user . However when I try to use it in index.php template it is not working. It is showing no href link. I don't see anything wrong with the code.

     $author_id = get_the_author_meta('ID');
     $test=get_field('url', 'user_'.$author_id);
      ?>
    <div class="image"><a href="<?php echo $test; ?>" target="_blank"><?php echo $gravatar?></a>
    </div>

1 Answer 1

1

You need to specify the id of user:

For example:

get_field('url', 'user_1');

This code returns the url field of user with id = 1

Sign up to request clarification or add additional context in comments.

8 Comments

+1 - @Dev B - check out the Get a value from different objects portion of the get_field() docs for more information
So I Used $author_id = get_the_author_meta('ID'); <?php $test=get_field('url', $author_id); ?> <div class="image"><a href="<?php echo $test; ?>" target="_blank"><?php echo $gravatar?></a></div> Still there is no URL available in the href.
@Dev B do not use $author_id but 'user_' . $author_id;
The issue is that I am the admin user and The custom field is available only to the authors. What you are saying is that I should use like this:- $my_post = get_post( $id ); $userid= $my_post->post_author; $test=get_field('amazon', $userid);
@Dev B. You just need to get the user id and add it to the string 'user_'. And pass the result to get_field second parameter.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.