[wp-hackers] $wpdb->prefix

Chris McCoy chrismccoy at cogeco.ca
Sat Jun 13 21:14:29 UTC 2015


you would apply a join

http://wordpress.stackexchange.com/questions/8503/optimize-multiple-taxonomy-term-mysql-query 


here are a few examples in here.






On 2015-06-13, 4:27 PM, "wp-hackers on behalf of Haluk Karamete" <wp-hackers-bounces at lists.automattic.com on behalf of halukkaramete at gmail.com> wrote:

>Actually using wpdb->get_results could have just done the job for me ( but
>I need a more complex SQL that a simple one as follows )
>
> $SQL = "
>    SELECT other_prefix_posts.*
>    FROM other_prefix_posts
>    WHERE ( other_prefix_posts.ID < 10 )
>    AND other_prefix_posts.post_status = 'publish'
>    AND other_prefix_posts.post_type = 'post'
>    ORDER BY other_prefix_posts.post_date DESC
> ";
>
> $posts = $wpdb->get_results($querystr, OBJECT);
>
>This won't cut my need cause I need post_tags and category terms sprinkled
>over this SQL & that's where the buck stops.
>
>
>
>
>
>
>
>On Sat, Jun 13, 2015 at 9:02 AM, Stephen Harris <contact at stephenharris.info>
>wrote:
>
>> 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.
>>>
>>
>> _______________________________________________
>> 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