[wp-hackers] $wpdb->prefix

Stephen Harris contact at stephenharris.info
Sat Jun 13 16:02:40 UTC 2015


This method isn't without it's difficulties, because of caching and 
globals and the like.

You could attempt to mimic WordPress' switch_to_bog() adapted for a 
non-multisite instance. E.g. flush cache, reinitialise use roles etc. 
This would involve flushing the cache completely 
($wp_object_cache->switch_to_blog()) won't work here because you're not 
in a multisite environment).

But I'm not convinced it would be plain sailing from there either :).

Depending on what is required, simply reading the first site's RSS feed 
and rendering that might the most straightforward solution.

Stephen


On 13/06/15 14:04, J.D. Grimes wrote:
> Depending on what you are doing, you might not want or need multisite. In that case, this should work:
>
>
>
> $old_prefix = $wpdb->set_prefix( $site_1_prefix );
>
> // get posts, etc., here.
>
> $wpdb->set_prefix( $old_prefix );
>
>
>
> See wpdb::set_prefix(): https://developer.wordpress.org/reference/classes/wpdb/set_prefix/
>
> -J.D.



More information about the wp-hackers mailing list