How to mass-change custom field content with phpMyAdmin? (5 posts)

  1. parakeet
    Posted 9 years ago #

    Hi. I need to mass-change the content of several custom fields; I'm told phpMyAdmin is the best way to do this.

    For example, for posts in category #4, I need to change the content of the syndication_source field from...

    Yahoo! News Results for "john doe"

    ... to ...


    With help, I cobbled together these queries...

    select * from wp_postmeta where post_id in ( select post_id from wp_post2cat where category_id = '4' );
    update wp_postmeta set meta_value = 'Mydomain.co.uk' where meta_value = 'Yahoo! News Results for \"john doe\"' and post_id in ( select post_id from wp_post2cat where category_id = '4' )

    However - whilst the query executes successfully, I am not seeing any change take effect and phpMyAdmin reports: "# MySQL returned an empty result set (i.e. zero rows)."

    Can anyone help me construct a query set to accomplish this? I'm also going to want to do similar for custom fields like syndication_permalink, which is a URL.

    Note that the posts I'm talking about above in category #4 may also belong to other categories.


  2. parakeet
    Posted 9 years ago #

    What I would also like to do is mass-remove a string like " (Some Text)" from a post title where it occurs.

  3. parakeet
    Posted 9 years ago #

    Anything... ? :(

  4. parakeet
    Posted 9 years ago #

    Okay, I've managed to get some replacement functionality working by inserting this into my index.php and hitting the page once (credit Firas from #wordpress)...

    $post_ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id = '4'");
    foreach($post_ids as $post_id) {
    $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = 'My New Source Name' WHERE meta_key = 'syndication_source' and post_id = '$post_id'");

    ... and I can change the id to edit each source name.

    But I'm still missing a couple of things...
    ie. How can I create a new value (not a replacement) for the syndication_feed_id and syndication_source fields, *where no value existed* (ie. not update but create?).


  5. Firas
    Posted 9 years ago #

    INSERT INTO $wpdb->postmeta (meta_key, meta_value, post_id) VALUES('syndication_feed_id', 'your value', '$post_id'")

    It's all just mysql more than a WP question.

Topic Closed

This topic has been closed to new replies.

About this Topic