Help running a MySQL query to update all wp_#_options tables in a Multisite install

Got a partial solution, but requires VPS to run it as shared hosting has a restriction on what you can do with a cursor. Anyway, DROP PROCEDURE IF EXISTS `update_all_options`; DELIMITER // CREATE PROCEDURE update_all_options( IN db varchar(255), IN theoption varchar(255), IN set_val VARCHAR(255) ) BEGIN DECLARE table_val VARCHAR(255); — Declare variables used just for … Read more

Tons of Twitter rows in my database

Here is a bait-and-switch approach to deleting all those rows: CREATE TABLE wp_posts_new LIKE wp_posts; ALTER TABLE wp_posts_new DISABLE KEYS; INSERT INTO wp_posts_new SELECT * FROM wp_posts WHERE post_type’http’ AND post_title<>’GET http://twitter.com/statuses/user_timeline/@xcentric.json?count=100′; ALTER TABLE wp_posts_new ENABLE KEYS; ALTER TABLE wp_posts RENAME wp_posts_old; ALTER TABLE wp_posts_new RENAME wp_posts; Now start using you website. When you are … Read more

Get multiple custom field values in a $wpdb query [duplicate]

You are going to have to JOIN twice on the postmeta table. Something like: SELECT $wpdb->posts.ID, $wpdb->posts.post_title, $wpdb->terms.name, wpcflat.meta_value AS latitude, wpcflong.meta_value AS longitude FROM $wpdb->posts /* First Join */ LEFT JOIN $wpdb->postmeta as wpcflong ON $wpdb->posts.ID = wpcflong.post_id /* Second Join */ LEFT JOIN $wpdb->postmeta as wpcflat ON $wpdb->posts.ID = wpcflat.post_id LEFT JOIN $wpdb->term_relationships … Read more

wp_admin edit.php slow with lots of queries

One way to do this (and yes, it is ugly and hackish) is to create a custom page having a custom page template that draws out all of your posts and creates the proper admin url links for each one. For example: <?php /* Template Name: View Posts Quickly */ if ( !is_user_logged_in() ) { … Read more

How to check for empty and not a failure

You test for a fail by explicitly testing for false: if (null === $mypostids) { /* it failed */ } NB: three equals signs! you want to check for identical, not just equivalent edit: originally said false, changed to null after looking at get_result() function in source.