Connect another DB and fetch records from some tables

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 … Read more

Migrating from Existing MySQL Setup to WordPress

If you’re fairly well-versed in WordPress plugin development, you could write a couple plugins, one to create your users with wp_create_user(), and another to insert your articles as Posts using wp_insert_post() (which, among other things, allows you to specify the post_author on each post that you insert). If you’re not so comfortable writing plugins, then … Read more

Site running slow on new server?

Your site is very, very heavy at 4+ megs. Lighten it up; see http://gtmetrix.com/reports/www.moseleycoachsales.co.uk/eyz4qxQx Fix the code errors, such as not specifying image dimensions, not correctly scaling your images, not optimizing your images, setting browser caching and expires headers, etc. Your site speed has very little to do with one 404 for one style sheet. … Read more

WordPress not reflecting changed of the database

I’d suggest to try using this: http://interconnectit.com/products/search-and-replace-for-wordpress-databases/ As @s_ha_dum has said, it looks like you’ve missed something. The above script automates the process of updating all URL references within the database when changing folder/URL and is much quicker and easier. You’ve probably missed some entries as some references to the URL are stored as serialized … Read more

I want to select the from values from database in WordPress? [closed]

Read the wpdb docs and don’t forget to protect your query: global $wpdb; $table_name = $wpdb->prefix . “item”; $login_name = sanitize_user( $_POST[‘login_name’] ); //assuming you’re dealing with username $prepare = $wpdb->prepare( “SELECT * FROM $table_name WHERE uname = %s”, $login_name ); $myrows = $wpdb->get_results( $prepare ); //output results echo ‘<pre>’ . print_r( $myrows, true ) … Read more

Add “Category” to Mysql Query

If I’m not missing something, the below should work for you. It is pretty much straight from the Codex: WP_Query – Custom Field Parameters. Do it like this: $args = array( ‘post_type’ => ‘post’, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘color’, ‘value’ => ‘red’, ‘compare’ => ‘=’ ), array( ‘key’ => ‘size’, … Read more