here is what I did with slight change as per your need. May be it will helpful for you. 🙂
function fetch_news()
{
global $wpdb;
$wpdb_backup = $wpdb; // backup existing instance
$wpdb = new wpdb( NEWS_DB_USER, NEWS_DB_PASSWORD, NEWS_DB_NAME, NEWS_DB_HOST ); // create new db instance
wp_set_wpdb_vars(); // add variable
$news_sql = $wpdb->get_results("SELECT * FROM rss_news"); // your query to external db table using $wpdb object
or
$news_sql = mysql_query("SELECT * FROM rss_news"); // your query to external db table
$wpdb = $wpdb_backup; // restore old instance
return $news_sql;
}
Related Posts:
- Column count doesn’t match value count at row 1
- ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
- MySQL string replace
- MySQL error 2006: mysql server has gone away
- ERROR 2003 (HY000): Can’t connect to MySQL server on localhost (10061)
- “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”
- #1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’
- What is the definition of cardinality in SQL
- How to restart remote MySQL server running on Ubuntu linux?
- Host ‘xxx.xx.xxx.xxx’ is not allowed to connect to this MySQL server
- what does “/index.php?admin/admin_dashboard” in my url mean
- How to join two tables by multiple columns in SQL?
- How to get size of mysql database?
- SQL – Update multiple records in one query
- Difference between VARCHAR and TEXT in MySQL
- MySQL Error 1093 – Can’t specify target table for update in FROM clause
- MySQL: Invalid use of group function
- mysqladmin: connect to server at ‘localhost’ failed
- mysql update multiple columns with same now()
- Usage of MySQL’s “IF EXISTS”
- Simple Random Samples from a Sql database
- What does SQL clause “GROUP BY 1” mean?
- LAST_INSERT_ID() MySQL
- Generating a random & unique 8 character string using MySQL
- MySQL > Table doesn’t exist. But it does (or it should)
- SQL select only rows with max value on a column
- Trying to perform MINUS operation in MySQL
- How do I find which transaction is causing a “Waiting for table metadata lock” state?
- Getting java.sql.SQLException: Operation not allowed after ResultSet closed
- How to create a foreign key in phpmyadmin
- Can’t create test file lower test start server mysql
- MySQL delete multiple rows in one query conditions unique to each row
- Create boolean column in MySQL with false as default value?
- SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
- Is there a naming convention for MySQL?
- CAST to DECIMAL in MySQL
- Failed to Connect to MySQL at localhost:3306 with user root
- How do you properly prepare a %LIKE% SQL statement?
- Set page template for all pages?
- Optimize Multiple Taxonomy Term MySQL Query?
- What specific database privileges does WordPress need?
- SQL query to update post_date (one post = one single date & time)
- My WordPress site always displays a cached version of its homepage
- How to copy post titles to post slug in phpmyadmin
- If I consider changing my WordPress DB tables to InnoDB, will it have an effect on the way WordPress works?
- Proper way to work with wpdb to get user’s firstname
- How to change post format from Aside to Image for all posts?
- How to add and SQL query of posts only published
- Slow Mysql Queries
- Database: Custom table: sprintf value for DateTime column
- What is the most secure way to set up the MySQL user in WPMU?
- Find duplicate posts with same slug and author
- WP_USE_EXT_MYSQL
- writing inner join in wpdb
- Distinction on meta value on pre_get_posts
- When WordPress Default table, Echo Success. When Plugin Table, Echo Blank
- How do I join a $wpdb query with user meta using default value if not exist?
- mySQL statment count of post in each category and sub category
- How to translate this mySQL query to $wpdb query
- $wpdb to insert html form information
- Proper usage of $wpdb->update()?
- MySQL 5.5 upgrade ‘broke’ WordPress [closed]
- Separate DB by yearly archive of WordPress
- Paypal Post IPN handeling nightmare
- What should a WordPress developer know about MySQL? [closed]
- Copyright: Get first and last date of post type
- Update MySQL query so that it functions again
- Is there a page length limit?
- Query posts by custom taxonomy and sort by post_modified
- WordPress $wpdb get posts from category and sort by custom meta
- Create a form with custom autocomplete address field and CSV import values
- WordPress insert query is not working : Showing no Error
- Some Post Content Does Not Show Up In DB Search
- Array Formation Issue
- Migration problems with mysql: Operation not allowed when innodb_forced_recovery > 0 [closed]
- WordPress $wpdb no result
- How can I view my site directly from WordPress dashboard?
- (WP List Table) How to sort by SKU and Custom Fields?
- User set date and time from frontend doesn’t get stored into database
- get posts whether meta_key exists or not
- when using $wpdb sudden connection rejection without changing anything. Access denied, with errors from repair tool
- How to bulk delete a certain part of all wordpress posts
- When I add metadata, metavalue length is added in to the value in some cases
- edit_user_created_user hook – using to update Groups
- Mysql Error in querying form entries in Gravity Form plugin
- update_option returns false in AJAX, how to debug?
- WordPress database error Duplicate entry for key ‘slug’
- Improving performance of SQL sub-queries in WordPress
- Saving custom term value to the database in new table
- MySQL errors after a WordPress clone
- `#1215 – Cannot add foreign key constraint
- How to restore: Database intact but folders deleted
- XML RPC post produces immediate revision with odd post_date_gmt
- MYSQL Join on meta key value?
- Complicated MySQL Query
- problem with quotes on new post
- Why does the MySQL command line tool ignore the –port parameter?
- Postgres equivalent to MySQL’s \G?
- How to find source of these strange SQL queries?
- How to reduce uncached page generation time?