WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
[resolved] Add Custom Fields to Sidebar? (3 posts)

  1. Treebeard
    Member
    Posted 1 year ago #

    I have some custom fields that are shown on the homepage and they're working perfectly. But when I try to include those in the sidebar so they appear on all pages in the site that use the Page template, the custom field areas are blank. Why is that? Am I missing something?

    All I'm doing is including the same exact code that I have on the homepage template, in the sidebar template, but nothing happens.

    Anyone know if this is a bug, if this is something that can't be done, or if I'm just doing this incorrectly?

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  2. Harrison O.
    Member
    Posted 1 year ago #

    That's because the custom field is in the sidebar, outside the loop. That is, the custom field call does not know which page it is and so its blank.

    You can use a WP_query function to create another loop on the sidebar and just call the custom field:

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'customField', true);
    ?>
  3. elliotcondon
    Member
    Plugin Author

    Posted 1 year ago #

    Hi guys,

    If you use the get_field or the_field functions, ACF will do all this for you!

    http://www.advancedcustomfields.com/docs/functions/get_field/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.