Upgrade DB Loop – WordPress DB Version Conflict

I’ve had this issue before. I stumbled on a really old article from Mark Jaquith on forcing an update. The plugin I’m linking to was originally made to update from 1.5.x to 2.0.x. I was in a bind so I gave it a shot. I did have recent back-ups for my DB so I wasn’t … Read more

Export SQL query based on custom field?

Change your query to: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON wp_postmeta.post_ID = wp_posts.ID WHERE ( wp_postmeta.meta_key = ‘Color’ AND wp_postmeta.meta_value IS NOT NULL ); That way it only gets the data in wp_posts, but still filters based on your criteria.

Php Mysql Terms

What you just found in your database is the serialized form of an array. For the sake of understanding the concept, see the PHP manual on the serialize function. As an aside: Apart from the fact, that you found this in a WP database though, this question is not WP specific and actually beyond the … Read more

PHP variables in mysql query

To insert a new row: global $wpdb; $wpdb->insert( ‘wp_mytable’, array( ‘product’ => $product ), array( ‘%s’ ) ); For the sake of completeness, $wpdb->update is used to update an existing row and requires an additional WHERE clause, as would a “regular” SQL query. For example: global $wpdb; $wpdb->update( ‘wp_mytable’, array( ‘product’ => $product ), array( … Read more

Pull post name from value of a specific meta key

Here is a function that loops through all your posts and checks if the post_name is equal to your post_meta_value. If not it updates the post_name to whatever the post_meta value is. function wpse_get_update_posts() { $posts = get_posts( array( ‘posts_per_page’ => -1 ) ); foreach ( $posts as $post ) { if ( $post->post_name == … Read more

WordPress $wpdb no result

Your specific issue in that code is that you’re missing the quote marks around the $code. $query .= ‘WHERE code=”.$code; Should be: $query .= “WHERE code= “‘.$code.'”‘; In the long run, you should indeed use prepare() properly, but this is the specific problem with the code you posted.

Way to extract wordpress data from folder backup

There’s two elements to this: Restoring the mySQL database which hopefully resided in your wamp folder. This will be where the actual post data is in. See Restoring MySQL database from physical files Restore MySQL database folder from a recovered Hard Disk   Restoring the files themselves. The most straightforward way to do this will … Read more

querying user bookmarks from a large number of bookmarks

It looks like the default get_bookmarks() http://codex.wordpress.org/Function_Reference/get_bookmarks is using this query: SELECT * FROM wp_links WHERE 1=1 AND link_visible=”Y” ORDER BY link_name ASC; You can check the function in /wp-includes/bookmark.php. The get_bookmarks() function has limit and order parameters that you might find helpful. The option get_bookmarks(“limit=5”) gives this query: SELECT * FROM wp_links WHERE 1=1 … Read more

SQL Statement – Mass Delete Custom Post Types

Trust you have backed up your wordpress database. In any case, as the article suggests, worth trying with a select statement first to see which posts are returned: SELECT DISTINCT ID, post_title, post_type, post_status, d.taxonomy, e.name FROM wp_posts a LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id ) LEFT JOIN wp_postmeta c ON ( … Read more