[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 05:28:58 UTC 2013
TY
On Wed, Dec 11, 2013 at 11:20 PM, Dion Hulse (dd32) <wordpress at dd32.id.au>wrote:
> For your particular use-case, you should be able to add
> global $wpdb, $wp_query;
> to before the include_once() line.
>
> However, you may want to re-test under 3.8, I believe we altered a few
> things in 3.7&3.8 to work better when included within a function..
>
>
>
>
> On 12 December 2013 15:13, Chris Richard <chris.richard at ratehub.ca> wrote:
>
> > 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
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list