Support

Account

Home Forums General Issues ACF5 in widgets

Solved

ACF5 in widgets

  • How do I call ACF custom field data saved to the widget itself?

    I thought perhaps something like this but no dice-

    
    $widget_id = $args['widget_id'];
    $myField = get_field('ACF_FIELD_NAME', $widget_id);
    
  • Here’s how to do it-

    public function widget( $args, $instance ) {
    extract( $args );
    $widget_id = $args['widget_id'];
    $MYVARIABLE = get_field($widget_id.'_ACFFIELDNAME', 'widget');
    echo $MYVARIABLE;
    ...
    }
    
    public function form( $instance ) {
    $widget_id = $this->id;
    ...
    ?>
    
  • If you use widgets a lot, consider checking out http://acfwidgets.com

    Might speed up your workflow some!

    Cheers!

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

You must be logged in to reply to this topic.