Support

Account

Home Forums General Issues Values not displaying in Sidebar

Solving

Values not displaying in Sidebar

  • Hi,

    I’m still having some issues with ACF. Currently we have some custom fields that are added to each blog post. I’m having issues with getting the values to display on the frontend blog post sidebar. The sidebar is the same on all blog posts, and the ACF values should display.

    If i place the shortcode inside the actual blog post, it will display.

  • Hi @bwsmedia

    The issue you had mostly occurred because you were trying to execute the get_field() or the_field() function outside of The Loop. To fix it, you need to pass the post/page ID as the second parameter to the get_field() or the_field() function like this:

    get_field('custom_field_name', 99)

    Where “99” is the post/page ID where the custom field is assigned. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/get_field/.

    Hope this makes sense 🙂

  • Hi James,

    Thanks for the reply! I was able to use the shortcode [acf field="header_title" post_id="350"] in the sidebar and it displayed correctly. However, we’re using PHP and need the post_id to generate automatically since we cannot enter it manually for each sidebar/post. Is this possible?

  • Hi @bwsmedia

    If there’s nothing else on your page that modifies the $post global variable, you should be able to do it like this:

    global $post;
    the_field('custom_field_name', $post->ID);

    This page should give you more idea about it: http://wordpress.stackexchange.com/questions/170358/when-to-use-global-post-and-other-global-variables.

    I hope this helps 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Values not displaying in Sidebar’ is closed to new replies.