Home » Topics » Priority Support » Get ACF Widget values outside template

Get ACF Widget values outside template

ACF Widgets Support Priority Support Get ACF Widget values outside template

This topic contains 3 replies, has 2 voices, and was last updated by  Grégoire Noyelle 3 years, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #90697

    Grégoire Noyelle
    Participant

    Hi
    I want to know the best way to get AFC widget values outside the widget template.
    For eg in function.php to use some wp_head hook if a value is available.
    Thanks !
    Grégoire

    #90716

    Daron Spence
    Keymaster

    Hey Gregoire,

    The formula you are looking for is get_field("your_key", "widget_$widget_id" ); where $widget_id is the unique instance of the widget. This can be difficult to grab dynamically though.

    I would look into the global $wp_registered_sidebars to see if that contains instances of the widget that you are looking for. I do know for a fact that sidebar data is stored in the wp_options table so you may be able to query that directly to get the unique instantiated widget ID as well.

    #90739

    Daron Spence
    Keymaster

    Ah yes, here is is.

    $sidebars_widgets = get_option('sidebars_widgets');

    will get you an associative array for each sidebar and the widgets that have been added to that sidebar. The unique id you are looking for will look something like `my_widget_name-43′ most likely. 43 being representative of the 43rd instance of that widget over your site’s life.

    #90851

    Grégoire Noyelle
    Participant

    Hey Daron,
    Thanks a lot for your quick answer.
    That’s perfect.
    Cheers,
    Grégoire

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

You must be logged in to reply to this topic.