Home › Forums › General Issues › How to display the value from the latest post id in the widget › Reply To: How to display the value from the latest post id in the widget
That’s because the shortcode is trying to get the global
$post variable on your site, which doesn’t have the correct post ID if you put it in a widget.
In this case, you need to modify the template where you show the widget (usually sidebar) and show the data manually like this:
// get the latest post $latest_posts = get_posts("post_type=post&numberposts=1"); // show the custom field echo the_field('p1', $latest_posts->ID);
This page should give you more idea about it: https://www.advancedcustomfields.com/resources/displaying-custom-field-values-in-your-theme/.
I hope this makes sense 🙂
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!
© 2022 Advanced Custom Fields.