[wp-hackers] Using WP_Query "outside" of Wordpress by including wp-load.php inside a function

Chris Richard chris.richard at ratehub.ca
Thu Dec 12 04:13:12 UTC 2013


I get a couple referencing errors when trying to include wp-load.php from
within a PHP function on WP Multi Site.

public static function getEntries($options) {
@include_once('wordpress/wp-load.php');
if (function_exists('switch_to_blog')) {
switch_to_blog('...');

$options = array_merge(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 10,
),
$options);

$query = new WP_Query($options);
...

After poking around a bit I found that I can make two small edits to make
this whole scenario work nicely.

in ms-settings.php:

global $wpdb;

and in wp-settings.php:

$GLOBALS['wp_query'] = $wp_the_query; // instead of $wp_query = ...

SO everything works great until we upgrade and all the changes get
clobbered. These changes are pretty minor - is this something that could be
committed? Does WP do pull requests?

Chris


More information about the wp-hackers mailing list