Home Forums General Issues Retrieve Custom Field in Sidebar & Footer


Retrieve Custom Field in Sidebar & Footer

  • Hi all….

    I’m looking to retrieve custom fields from a post from the sidebar and from the footer. EG. I update my post with data in the custom fields and then display that data in the sidebar. Is this possible?

    Also in the case where I have my homepage set to latest posts, how can add customs fields to it? Is it a case of creating a dummy page and taking the custom fields from that dummy page?


  • Hi

    In order to display custom field values in the sidebar and the footer.

    You will need to provide a second parameter of the post id to the the_field/get_field function.

    For example

    $post_id = null; // current post
    $post_id = 1; // post 1
    $post_id = "option"; // options page
    $post_id = "options"; // same as above
    $post_id = "category_2"; // target a specific category
    $post_id = "event_3"; // target a specific taxonomy (this tax is called "event")
    $post_id = "user_1"; // target a specific user (user id = 1)
    the_field( "text_field", $post_id );

  • look:

    not properly
    the_field( "text_field", $post_id );


    $mypost_id = get_queried_object()->ID;   
    the_field( "text_field", $mypost_id );
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Retrieve Custom Field in Sidebar & Footer’ is closed to new replies.