I'm trying to figure out how I can utilize WP_Query and WP_Meta_Query outside of the WordPress install, for server Cron jobs.

I've tried including wp-load.php but this also brings in plugins like WooCommerce into the mix and I'm getting all kinds of header warnings, etc. I just need to be interacting with the database, not all of the theme and plugin methods.

This is an example of the warnings that I currently get:

Notice: wp_woocommerce_session_d34eac23ade02d0820a9089e923eed79 cookie cannot be set - headers already sent by /var/www/vhosts/mywebsite.com/dev.mywebsite.com/wp-content/plugins/woo-product-slider/main.php on line 214 in /var/www/vhosts/mywebsite.com/dev.mywebsite.com/wp-content/plugins/woocommerce/includes/wc-core-functions.php on line 733

Fatal error: Cannot redeclare get_query_var() (previously declared in /var/www/vhosts/mywebsite.com/dev.mywebsite.com/wp-includes/query.php:26) in /var/www/vhosts/mywebsite.com/dev.mywebsite.com/wp-includes/query.php on line 29
  • It sounds like you're including wp_head() as well. Could you post the rest of the code that contains your wp-load.php include? Sep 2, 2016 at 23:00
  • wp_head() is not included... at least not that I know of. The only thing that is being used is wp-load.php
    – dcolumbus
    Sep 7, 2016 at 16:31
  • Is wp_load.php at the very top of the file? There shouldn't be anything before it. Sep 7, 2016 at 18:41

1 Answer 1


This is what worked for me:

require_once 'wp-config.php';
global $wpdb;
$args = array(
            'post_type' => 'product',
            'posts_per_page' => -1,
$Query= new WP_Query($args);

You can use similar way to achieve what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.