ACF Widgets › Support › General Support › ACFW with the_widget()
Tagged: custom widget, shortcode, the_widget()
- This topic has 6 replies, 2 voices, and was last updated 5 years, 7 months ago by
Daron Spence.
-
AuthorPosts
-
May 13, 2015 at 4:02 PM #2178
oliwer helsen
ParticipantHey,
I try to get my custom created widget with a shortcode and for that i am using the_widget function built in to wordpress.
How do i now the type of the widget that are required for the_widget()?My code:
add_shortcode( 'widget', 'my_widget_shortcode' ); function my_widget_shortcode( $atts ) { // Configure defaults and extract the attributes into variables extract( shortcode_atts( array( 'type' => '', 'title' => '', 'scheme' => 'light' ), $atts )); $args = array( 'before_widget' => '
', 'after_widget' => '', 'before_title' => '', 'after_title' => '', ); ob_start(); the_widget($type, $args, $atts); $output = ob_get_clean(); return $output; }For using this in a textfield:
[widget type="and-the-type-here-that-i-need"]
Big thanks in advance!
//O
-
This topic was modified 5 years, 8 months ago by
Daron Spence.
-
This topic was modified 5 years, 8 months ago by
Daron Spence.
-
This topic was modified 5 years, 8 months ago by
Daron Spence.
May 13, 2015 at 4:17 PM #2186Daron Spence
KeymasterHello,
I think the data you are looking for can be found in the
$GLOBALS['wp_widget_factory']
variable. It has an array of all the registered widgets on the site. From there, you can see what name is being given to the widget.I believe the default naming structure is
ACF_Widget_1
where the number “1” is the post ID of that widget (since the plugin uses custom post types). If you are creating your widgets through the ACFW filters, then they would be namedACF_Widget_your/custom/id/here
. Let me know if that helps. Though at this point, using the widgets like this isn’t really a good idea. I would strongly suggest looking into something more like an options page where they enter data instead of using a widget. However, you know your user, which is always the most important thing 🙂May 13, 2015 at 4:38 PM #2187oliwer helsen
ParticipantThanks for replay:-)
Now i get this:
Notice: Undefined variable: widget_id in /Users/ioliwer/Projekt/Sigma/lff/wp-content/plugins/acf-widgets/includes/ACFW_Widget.php on line 73
When i ran this:
add_shortcode( ‘widget’, ‘my_widget_shortcode’ );
function my_widget_shortcode( $atts ) {
// Configure defaults and extract the attributes into variables
extract( shortcode_atts(
array(
‘type’ => ”,
‘title’ => ”,
‘scheme’ => ‘light’
),
$atts
));$args = array(
‘before_widget’ => ‘<div class=”box widget scheme-‘ . $scheme . ‘ “>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<div class=”widget-title”>’,
‘after_title’ => ‘</div>’,
);ob_start();
the_widget(‘ACFW_Widget_2139’);
$output = ob_get_clean();return $output;
}
Any idea?
May 13, 2015 at 4:43 PM #2188Daron Spence
KeymasterYou will need to add an extra argument to your
$args
array.'widget_id' => 'ACF_Widget/ID/here'
That should make it work. I think 🙂
May 13, 2015 at 4:57 PM #2189oliwer helsen
ParticipantOkey. We are now closer:-).
i try to use get_fields($acfw); but i dont get any data :-(.
Can i only use the_field()?
May 13, 2015 at 5:00 PM #2190Daron Spence
KeymasterNow here is the part where using
the_widget()
doesn’t really work. Widgets needs to reference and instance with the data. There isn’t a way to reference that data dynamically outside of the sidebar.Can you explain your whole process and how you’re using the “widget”. Definitely think we can find a solution 🙂
June 5, 2015 at 9:11 PM #2238Daron Spence
KeymasterHave you made any progress on this? 🙂
-
This topic was modified 5 years, 8 months ago by
-
AuthorPosts
- The topic ‘ACFW with the_widget()’ is closed to new replies.