Title: WP_Query not working in plugin
Last modified: August 20, 2016

---

# WP_Query not working in plugin

 *  Resolved [spencerpad](https://wordpress.org/support/users/spencerpad/)
 * (@spencerpad)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/wp_query-not-working-in-plugin/)
 * I made a plugin that schedules a php file to run and update certain posts meta
   once a day.
 * The problem is in the php file that runs once a day, when I load it into my browser
   gives me this error
 * Fatal error: Class ‘WP_Query’ not found in /nfs/c09/h04/mnt/140191/domains/dev.
   videogamecoupons.com/html/wp-content/plugins/Amazon-price-checker/Example.php
   on line 6
 * $query = new WP_Query( array( ‘cat’ => $pricecat, ‘meta_key’ => ‘ASIN’, ));
 * Is the line it is referring to. Do I need to include wordpress functions somehow
   to make WP_query work in a plugin?

Viewing 1 replies (of 1 total)

 *  Thread Starter [spencerpad](https://wordpress.org/support/users/spencerpad/)
 * (@spencerpad)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/wp_query-not-working-in-plugin/#post-2769287)
 * The answer in case anyone searches this was yes, I needed to include wp-blog-
   header.php which contains the WP_Query class.
    it is found in the root folder
   of my wordpress installation so I had to relative url it ../../../wp-blog-header.
   php

Viewing 1 replies (of 1 total)

The topic ‘WP_Query not working in plugin’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [spencerpad](https://wordpress.org/support/users/spencerpad/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/wp_query-not-working-in-plugin/#post-2769287)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
