Home › Forums › General Issues › User info by page name
I am new to ACF and WordPress, and am working on a project that requires userdata to be pulled by page name.
I have built a user form, which works perfectly. I am able to call data with <?php $user_info = get_userdata();?>. Unfortunately, there will be multiple pages using the template that this is built into.
First, is this possible? If so, how to go about it?
I managed to do this with <?php $user_info = get_userdata( $post -> post_author );?> , but am having difficulty with custom image fields.
Hi @sc-leslie
To get the custom field values from a user, please take a look at this page: http://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/.
I hope this helps.
Thanks James, I’m trying to apply fields as custom page styles. Color and text fields come up fine, but background images are not rendering. Do I need to apply them as a function first?
This is what I am using to identify the author inside my template. I chose to make a custom template because it will allow me to duplicate the page and set the author to specific person. Person will then be able to an account page I set up with custom user form, which includes two image fields (a logo and background), to customize their page.
<?php
$user_info = get_userdata( $post -> post_author );?>
These work:
<?php echo ” . $user_info->farm_name . “\n” ?>
<?php echo ” . $user_info->contact_number . “\n” ?>
<?php echo ” . $user_info->stream_name ?>
<?php echo ” . $user_info->app_name ?>
<?php echo ” . $user_info->background_color . “\n” ?>
<?php echo ” . $user_info->font_color . “\n” ?>;”>
I tried using the example, but that left me no fields rendering.
This is the closest I’ve gotten to a return of anything, in this case, the field id.
<?php echo ” . $user_info->background_image ?>
I do apologize for my lack of knowledge. Html has been much friendlier to me. I honestly paid someone a good sum to set this all up for me 2 years ago, but after a multitude of excuses, and finally ignoring me completely it’s obvious if I want something done, I’ll have to do it.
Hi @sc-leslie
You should be able to get the image by using this code:
<?php $background = get_field('background_image_field_name', 'user_'.$user_info->ID); ?>
<img src="<?php echo $background['url']; ?>" alt="<?php echo $background['alt']; ?>" />
Please change the “background_image_field_name” with the name of your custom field.
You can check the $background value by using this code:
echo '<pre>';
var_dump($background);
echo '</pre>';
If it doesn’t work, could you please share the JSON export of your field group and the PHP file of the template?
Thanks!
Hi James, yes I solved this a couple days ago, just been too busy to post.
I ended up with this:
<?php
$temp_post = get_post($post_id);
$author_id = $temp_post->post_author;
$background_main = get_field(‘background_image’, ‘user_’ . $author_id);
?>
background-image:url(‘<?php echo $background_main; ?>’)
The topic ‘User info by page name’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.