Hello developers,
Today, I am going to show you how to get widget field in acf using widget id.
Please follow below steps:
Step-1: Create acf fields which you want to get and choose widget location.
e.g. Here I take four fields and choose widget location in navigation menu(whatever you like). You can see in below screenshot.
Step-2: Now, go to Appearance>Widgets. In your widget drag and drop navigation menu.
You can see all fields in there. You can see in below screenshot.
Step-3: Here, widget id we have to used.
For get widget id put below code in functions.php file.
add_action('in_widget_form', 'awts_get_widget_id'); function awts_get_widget_id($widget_instance) { // Check if the widget is already saved or not. if ($widget_instance->number=="__i__"){ echo "<p><strong>Widget ID is</strong>: Pls save the widget first!</p>" ; } else { echo "<p><strong>Widget ID is: </strong>" .$widget_instance->id. "</p>"; } }
Step-4: Now, We have get all fields in our front end using below code.
<?php the_field('field_name', 'widget_' . $widget_id); ?>
Output
Hopefully this article useful for you.
Thankyou. 🙂