How to get widget content in WordPress based on it’s ID?

Question

I need to parse widget content based on it’s ID.

But a widget works like a function that pulls data based on it’s arguments, right? So when I pull the widget data, I can only get it’s arguments, not the actual output.

How can I parse the widget content based on it’s ID?

Example code:

// Update widget rounds automatically
function automatize_games_rounds($instance, $widget, $args){
    // Check if there is a caption
    if (isset($instance['caption']) && !empty($instance['caption'])) {
        // If there is, does it contain the word "round"?
        if (strpos(strtolower($instance['caption']), 'round')) {
            // If yes, it's the kind of widget I'm looking for. Let's get it's ID.
            $id = $args['widget_id'];
            // Now I need to parse the widget output to do some stuff based on it's content, but how can I get the widget output?
        }
    }
    return $instance;
}
add_filter('widget_display_callback','automatize_games_rounds',10,3);

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/how-to-get-widget-content-in-wordpress-based-on-its-id/">

How to get widget content in Wordpress based on it's ID?</a>
0
, , Lucas Bustamante 2 months 0 Answers 52 views 0

Leave an answer