[wp-hackers] $wpdb->prefix

J.D. Grimes jdg at codesymphony.co
Sat Jun 13 13:04:27 UTC 2015


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.

> On Jun 13, 2015, at 6:10 AM, Christian Wach <needle at haystack.co.uk> wrote:
> 
> Sounds to me like you should host both sites in a multisite instance.
> 
> Cheers,
> 
> Christian
> 
> 
> On 13 Jun 2015, at 03:06, Haluk Karamete <halukkaramete at gmail.com> wrote:
> 
>> I installed 2 WordPress sites but pointed the 2nd WordPress install to the
>> 1st one's database. Since I used a different table prefix for the 2nd one,
>> everything works.
>> 
>> This results that  I got 2 set of WordPress tables in the same database
>> while the 2nd one uses just a different wpdb prefix.
>> 
>> The question is...
>> 
>> How can I use the get_posts() ( or WP_Query for that matter) to query to
>> 1st WordPress's posts from the 2nd one?
>> 
>> Is there an argument that I can pass to the get_posts or to WP_query to
>> tell the WP to use a different prefix than the current installs
>> wpdb->prefix default?
>> 
>> 
>> Ideally, this ios what I'm looking for;
>> 
>> $args = array(
>> 'db_prefix' => 'xyz',
>> 'posts_per_page' => -1,
>> );
>> 
>> Is there something like the 'db_prefix' above ?
>> _______________________________________________
>> 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