Showing posts from another wordpress database
-
Hi guys,
I have a problem that has been bugging me for a few weeks now – have searched far and wide for a solution without success.
Firstly let me say I can’t do this by accessing a feed as I need information like custom fields which are not available via rss.
I have two wordpress installations as follows:
mydomain.com/core and mydomain.com/newsmydomain.com/core hosts my main site while mydomain.com/news hosts the news.
I have reason to separate the installations as I use the core site as a conventional site (and not a blog) that uses the post ids for a specific purpose and I can’t have the news posts incrementing the post id whenever news are posted.
Anyways, I need to show news posts from the news wordpress installation on the core website but I can’t find a solution to connect to the news database from the core database and get wordpress-structured posts.
I can do a custom query but I would really like to be able to use the inbuilt “get_posts” function rather then put together my own custom query for this.
I thought I could do something like this from my theme files but it doesn’t work:
global $wpdb;
$temp_wpdb = $wpdb;
$new_wpdb = new wpdb(DB_USER, DB_PASSWORD, ‘wp_news’, DB_HOST);
$wpdb = $new_wpdb;run WP_QUERY() with category filters etc…
put back the previously used wpdb object:
$wpdb = $temp_wpdb;The above code doesn’t work though.
Can anyone help please? I’d be ever so grateful.
- The topic ‘Showing posts from another wordpress database’ is closed to new replies.