CRUD operations using WordPress database API

Querying in WordPress is done by using the the wpdb variable. Be sure to always prepare your sql so WP can make it database safe. Example: global $wpdb; $rows = $wpdb->get_results( $wpdb->prepare( “SELECT * FROM `{$wpdb->prefix}TABLE_NAME` WHERE `var` = %d”, 1) ); Then you can loop through the data and output it as for example … Read more

when I fetch data from remote mysql database in wordpress built in wordpress function is not working?

The WordPress APIs rely on the global $wpdb object, you can define any arbitrary object of type wpdb but that doesn’t mean WordPress will use it. Instead, something akin to the following might be better: global $wpdb; $tempDB = $wpdb; $wpdb = new wpdb(DB_USER2, DB_PASSWORD2, DB_NAME2, DB_HOST2); // do your remote SQL stuff // perhaps … Read more

Should a child theme share the same theme options row as the parent, or should it have it’s own options row?

Neither. Theme options should be stored as theme mods, using get_theme_mod and set_theme_mod. Internally these map on to options, but it is the official way to store theme specific options, that way when you change themes you don’t get clashes, and your settings are preserved for if you ever change back. It’s the classic adage … Read more

Most recent post from another database

The WordPress wpdb class is a little different than the normal way of querying in that you run “vanilla” database queries. You can see documentation on the wpdb class on the WordPress docs: http://codex.wordpress.org/Class_Reference/wpdb#Run_Any_Query_on_the_Database Also, in regard to your code, you should be able to change the line here: $originaldb->query_posts( ‘posts_per_page=1’ ); To something like … Read more

How can I check email exists via a jquery keyup()?

I would use an AJAX request to a PHP script that does the lookup, which might look something like this on the jQuery side after document ready: // jquery $(‘#email-input’).live(‘change’, function() { //ajax request $.ajax({ url: “email_check.php”, data: { ’email’ : $(‘#email-input’).val() }, dataType: ‘json’, success: function(data) { if(data.result) { alert(‘Email exists!’); } else { … Read more