Support

Account

Home Forums ACF PRO Getting the Widget ID while outputting a widget

Solving

Getting the Widget ID while outputting a widget

  • I was trying to figure out how to use get_field() to display data from a widget per this help article: https://www.advancedcustomfields.com/resources/get-values-widget/

    I wanted to suggest including how to actually get the widget id when using WordPress’s Widget API and the widget( $args, $instance ) function.

    “If the widget is custom made, you can also customize the HTML output within the widget function in your widget class.”

    I’d suggest adding a sentence here that explains that the widget ID is available as follows:

    $widget_id = $args[‘widget_id’];

  • Thanks for the suggestion, and it’s probably a good idea, but the people that would make this change don’t frequent these forums much. The developer is too busy working on code. While it may sound strange, the best way to get these types of suggestions to the developer is to open a new support ticket https://support.advancedcustomfields.com/new-ticket/

  • Thank you so much for this. The help article didn’t work for me and I couldn’t figure out why. That one line saved me. Yes, definitely needs to be added.

  • @madtownlems Thank you! You’re absolutely right. The official help article – Get values from a widget – only explains how to override the default widget code, by placing the ACF code in functions.php. But when I write my own widget, I want the ACF code in the same widget file.. no need to separate and override.

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

The topic ‘Getting the Widget ID while outputting a widget’ is closed to new replies.