admin管理员组

文章数量:1127935


I am using `ACF` plugin to add a custom field to my widgets. After creating the field with the name `mobile_enable`, tried to get the value with the method explained in the ACF docs which is the following:
the_field('field_name', 'widget_' . $widget_id)

Inside the widget method we can get the widget_id like this:

public function widget( $args, $instance ) {
   $widget_id = $args['widget_id']
}

The problem I am having is that the following code returns null even after enabling the option with the checkbox:

$is_mobile_enabled = get_field('mobile_enable', 'widget_' . $args['widget_id']);
var_dump($is_mobile_enabled);

I am using `ACF` plugin to add a custom field to my widgets. After creating the field with the name `mobile_enable`, tried to get the value with the method explained in the ACF docs which is the following:
the_field('field_name', 'widget_' . $widget_id)

Inside the widget method we can get the widget_id like this:

public function widget( $args, $instance ) {
   $widget_id = $args['widget_id']
}

The problem I am having is that the following code returns null even after enabling the option with the checkbox:

$is_mobile_enabled = get_field('mobile_enable', 'widget_' . $args['widget_id']);
var_dump($is_mobile_enabled);
Share Improve this question asked Dec 27, 2023 at 9:57 MeMoMeMo 712 silver badges6 bronze badges 2
  • In your last snippet: 'mobile_enable' are you missing a "d"? – mayersdesign Commented Dec 28, 2023 at 10:03
  • No that is how I defined it

    本文标签: custom fieldgetfield for a widget value returns null ACF