Home › Forums › General Issues › How to var dump
I need to do a var dump on a custom profile image field so that I can see how the info is stored and make my front end plugin work in unison with this one. I named the field test_acf_upload I have found different var dump instructions over the net but I’m not understanding where to even put the function? In my themes custom functions file? Or what? And then where do I retrieve the information?
Thank you for any help!
test_acf_upload
should be the slug for your custom field. Insert this into your active theme’s functions.php file:
$field = get_field('test_acf_upload');
echo '<pre>'.print_r($field, true).'</pre>';
Thank you for that. Our server has been down all morning so I can’t try it yet but while I wait if you don’t mind answering…
Where will the answer or outcome of the above function be shown exactly?
Thanks!
It should be printed at the very top of your outward-facing theme, like on the home page. There is a chance that your theme’s CSS could hide or distort the output, so you might have to view your page source to see it.
I like to put a string in front that I know is unique so that I can Ctrl+F and search for the text, like so:
echo '<pre>testdump999: '.print_r($field, true).'</pre>';
There’s a pretty slim chance that “testdump999” will show up anywhere else on its own, so if I can find that then it’s the output I’m looking for.
I’ve tried pasting these exact codes but all it’s showing on the page or page source is <pre></pre>
Is $field correct for a profile field maybe? Could it be looking for a post field instead?
Aha, I missed that this was for a profile! It’s good that you’re seeing the <pre>
tags, but to get user profile fields you have to pass in the user ID prepended with “user_”.
http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-user/
So to get the field for user ID zero:
$user_id = 0;
$field = get_field('test_acf_upload', 'user_'.$user_id);
echo '<pre>'.print_r($field, true).'</pre>';
You could get the user ID with a variety of functions.
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.