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.
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.
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.
$user_info = get_userdata( $post -> post_author );?>
<?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.
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?
Hi James, yes I solved this a couple days ago, just been too busy to post.
I ended up with this:
$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; ?>’)
You must be logged in to reply to this topic.
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've just released ACF 5.12.3 with a security fix to prevent arbitrary file uploads to forms with ACF fields.— Advanced Custom Fields (@wp_acf) July 14, 2022
Now that we've released this update, we recommend updating your sites as soon as possible.
© 2022 Advanced Custom Fields.