• 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 …

    Domain.co.uk

    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.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter parakeet

    (@parakeet)

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

    Thread Starter parakeet

    (@parakeet)

    Anything… ? 🙁

    Thread Starter parakeet

    (@parakeet)

    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)…

    <?php
    $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?).

    Thanks

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to mass-change custom field content with phpMyAdmin?’ is closed to new replies.