Title: Can widget use data array generated by a plugin?
Last modified: August 21, 2016

---

# Can widget use data array generated by a plugin?

 *  Resolved [Scott McCulloch](https://wordpress.org/support/users/sinemac/)
 * (@sinemac)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/can-widget-use-data-array-generated-by-a-plugin-1/)
 * [mis-posted this in ‘plugins’ forum… reposting here… not sure how to delete the
   other]
 * I’m creating my first plugin and some widgets for a colleague’s site, and I thought
   I’d separate the data retrieval part from the data display part, but I seem to
   be missing something (if it’s even possible).
 * I’ve created a plugin that will query the database and return an array ($report_data)
   when certain conditions are met in the page url. I’ve got that working – print_r(
   $report_data) confirms that the correct data is returned on the correct pages.(
   I’ve got the ‘add_action’ for the plugin set to “loop_start” ).
 * Now I’d like to have my widgets use that data to generate content for display–
   tables, graphics, etc… but when I load the widget into the post, I get an error
   that its missing the argument required (i.e., the $report_data array isn’t being
   picked up by the widget).
 * Is what I’m trying to do even possible?
    If so, what might I be missing?
 * Thanks,
    Scott

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Mark Wilkinson](https://wordpress.org/support/users/wpmarkuk/)
 * (@wpmarkuk)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/can-widget-use-data-array-generated-by-a-plugin-1/#post-5156108)
 * Sounds to me like this could a variable scope problem:
 * [http://php.net/manual/en/language.variables.scope.php](http://php.net/manual/en/language.variables.scope.php)
 * Perhaps you need to globalise the variable used by the widget (`$report_data`)
 *  Thread Starter [Scott McCulloch](https://wordpress.org/support/users/sinemac/)
 * (@sinemac)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/can-widget-use-data-array-generated-by-a-plugin-1/#post-5156117)
 * Thanks Mark! That pointed me in the right direction and I got it working.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Can widget use data array generated by a plugin?’ is closed to new replies.

## Tags

 * [plugin widget](https://wordpress.org/support/topic-tag/plugin-widget/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [Scott McCulloch](https://wordpress.org/support/users/sinemac/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/can-widget-use-data-array-generated-by-a-plugin-1/#post-5156117)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
