Home » Topics » General Support » ACFW with the_widget()

ACFW with the_widget()

ACF Widgets Support General Support ACFW with the_widget()

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2178
    oliwer helsen
    Participant

    Hey,

    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.
    #2186
    Daron Spence
    Keymaster

    Hello,

    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 named ACF_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 🙂

    #2187
    oliwer helsen
    Participant

    Thanks 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?

    #2188
    Daron Spence
    Keymaster

    You will need to add an extra argument to your $args array. 'widget_id' => 'ACF_Widget/ID/here'

    That should make it work. I think 🙂

    #2189
    oliwer helsen
    Participant

    Okey. We are now closer:-).

    i try to use get_fields($acfw); but i dont get any data :-(.

    Can i only use the_field()?

    #2190
    Daron Spence
    Keymaster

    Now 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 🙂

    #2238
    Daron Spence
    Keymaster

    Have you made any progress on this? 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘ACFW with the_widget()’ is closed to new replies.