Non-Multisite setup:
You need to create another instance of the WPDB Class.
$newWPDB = new wpdb('Username','password','database','localhost');
$rows = $newWPDB->get_results("you-query-here");
On WordPress Multisite:
Does having WordPress MultiSite make things a lot easier or should we
stick with single installations?
There is the switch_to_blog() function available. You will need to restore_current_blog() after getting your results.
Note that you could cache the results, for example using the Transients API, to reduce server load on future requests.
Related Posts:
- WordPress Multisite – Create Default Post and New Category On New Site Install
- Site ‘Categories’: save an admin global setting with post metadata [closed]
- Including categories in search results
- Different post sort order within different categories
- How to add metabox for post of specific category
- How to get Category Id from Post Id ?
- Query posts from current year
- How to get a post content from another wordpress blog/site?
- Exclude category on blog list page
- How to choose a sort order (for posts) per category? (ideally when creating a new category)
- WordPress Child Category Display All Posts
- How to create post in WP network using WP-CLI
- Do I use custom post type or something else?
- Limit function to specific post category
- Query posts from different categories in multisite
- Display posts in alphabetical order for a particular category
- How to make search for the custom post type?
- How to display related posts by subcategory and not parent category
- Category Template: Need to display different content on first page of archives
- Multisite – Get current post id
- How to automatically apply a category based on the post title?
- Direct link to “New post” in specific category?
- Using permalinks, category slugs, and tag slugs
- How to limit posts by category
- How do I retrieve then print the currently viewed sub categories?
- Unable to restore from backup – how to obtain old blog posts?
- Get attachments for posts that belongs to a specific category
- How can I setup a relationship using categories in WordPress?
- Related posts by category not working right
- Set Default Category to Username
- How to Mysql select a list of posts with meta_values AND all relevant categories?
- Redirect to another page using contact form 7? [closed]
- Display post category in foreach loop
- Single.php – Get Current Parent Category
- get_the_category listing in hierarchial order
- How show categories in admin and get that selected to show posts in index
- Sort by last word in title
- Give posts a particular template based on the assigned category
- Show posts on front page only
- Post-Archive like a page in a specific subdirectory
- Post is in descendant category not working in home.php
- How to get posts ordered by using their categories?
- Hide parts of the post content after typing it’s name or searching it by category
- SQL Bulk Move old posts by one author to another category
- How to display only one category in a custom post type?
- load more posts by category
- Get only X number of categories
- Display Related Posts by Category in Random
- inserting a category into post
- Getting posts from some categories plus some individual posts
- Change layout of post depending on category
- How to show beneath posts the full category path?
- latest post showing up twice on posts page
- wp_list_categories() Exclude All Categories Except One
- Display Current Posts Category (with the most posts)?
- Only the most recent post is showing on my category page (working on localhost, not live site)
- Display default matabox of posts(add category) wordpress
- ACF date picker to trigger category change
- Get category slug of the Parent category of a Product
- How to get tags when using publish_post
- exclude particular category in api
- How do you change the permalink for posts for a single category?
- Make categories appear random
- Exclude posts in a category on one page but show those posts on a different page
- Excluding category from post navigation in WordPress?
- How to make a page show posts only from specific categories without editing php files
- Get posts from category from custom query
- How to show posts ordered by random [duplicate]
- How to Get Position of a Post from a category and tag
- Display new posts categories in separated divs
- Querying posts from current category, using a variable as array argument
- Add Categories To Custom Post
- Query posts from newest category
- Precedence of page permalinks over woocommerce product category links?
- Display Posts by Categories
- Ajax – Post Categories and Load More
- Need help writing loop to display posts by categories in separate divs
- Edit Posts Page but not category specific pages?
- Add category selection to function request
- Query post category & remove any post id
- Multiple Post Repeat for Related Post Loop by Category
- How to organise post by category and date
- Show post if in category
- How to display custom content in post with category XXX
- Displaying categories items among posts
- how to show posts on different pages if number of post per page is one
- Displaying different posts Via wp_list_categories()
- Is it possible to have different header style blog titles in different categories?
- Category pages vs single post pages
- Get image paths from RSS feeds
- Display ONLY Latest Post From Several Categories
- How do we display a certain category type on a page while hiding all others?
- Show all posts in category
- Polylang – display one post into 3 categories with different lang [closed]
- Export Posts Without Categories In An XML File
- wordpress category Description not allowed tag
- How to get a list of all posts and their categories?
- Adding content to the top of post’s based on their category
- How to specify a post category for the home (posts) page?
- Mismatch between posts count and actual list in admin posts page