WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had used the ZD Video Plugin for WP a long time, and now, since my move to WP 3.0.2, it doesn't work anymore. To embed a YouTube video using the plugin, I would just write


Now I need to go back to plain YouTube embedding. How do I write a MySQL query that searches for [zdvideo]*[zdvideo] and replaces it with *?

share|improve this question
up vote 5 down vote accepted

What about these two queries?

UPDATE wp_posts SET post_content = REPLACE(post_content, '[zdvideo]', '');
UPDATE wp_posts SET post_content = REPLACE(post_content, '[/zdvideo]', '');
share|improve this answer
That'll only work if entering the YouTube URL is enough for his purpose. If there are things like <div>[zdvideo]...[/zdvideo]</div> the oEmbed functionality will be broken. – Denis de Bernardy Dec 6 '10 at 15:14
@Denis: If he wants to use the oEmbed stuff, I think you can also replace [zdvideo] with [embed], which will work even if the URL is not on a single line. – Jan Fabry Dec 6 '10 at 22:44
Thanks for the tip! Now if I want to replace all instances of http://youtube.com with httpv://youtube.com, I can use the REPLACE function as shown above, right? – GPX Dec 8 '10 at 8:36

Best I'm aware, MySQL doesn't have much of a regexp replace functionality -- not to mention its very clunky regexp syntax. So this is easiest to do at the php level. Start by fetching all posts that have the shortcode:

$posts = $wpdb->get_results("
SELECT ID, post_content
FROM $wpdb->posts
WHERE post_content LIKE '%[zdvideo]%'

And then loop through the result:

foreach ($posts as $post) {
  $post->post_content = preg_replace(
    "$1", # $1 holds the url... format as needed

  # Be sure to verify on a few posts before actually saving...
  # var_dump($post->post_content);

  UPDATE $wdpb->posts
  SET post_content = '" . $wpdb->escape($post->post_content) . "'
  WHERE ID = " . intval($post->ID)
share|improve this answer
Shouldn't the $wpdb->escape($post->post_content) be wrapped in single quotes? Then the whole row would be something like............................................................................‌​......................................................... SET post_content = '" . $wpdb->escape($post->post_content) . "' – jave.web Nov 12 '15 at 9:54
@jave.web: good catch. – Denis de Bernardy Nov 12 '15 at 9:57
NP, otherwise I used this approach in my solution and it works - so I can confirm this approach works :) – jave.web Nov 12 '15 at 10:30

or use the plugin Search & Replace, makes easy for use sql inside WP; use the like statement and give you an gui for search/replace strings in content and other tables.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.