Forums

[resolved] MySQL WordPress Database query help needed (3 posts)

  1. JaneLitte
    Member
    Posted 4 years ago #

    I am not sure if anyone here can help me, but I want to do a search and replace in my database. There is a word that is used in certain post titles that I want removed.

    This is the query I have devised, but I am not getting the end of the query correct:

    UPDATEwp_postsSET post_title = replace( post_title, 'REVIEW:', '' ) FROMwp_termsWHEREterm_id=9 LIMIT 0

    I want to search the database for all posts with the term (formerly category) = 9.

  2. Kafkaesqui
    Moderator
    Posted 4 years ago #

    This should do:

    UPDATE wp_posts AS p
    INNER JOIN wp_term_relationships AS tr ON p.ID=tr.object_id
    INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id=tt.term_taxonomy_id
    SET post_title = replace( post_title, 'REVIEW:', '' ) WHERE tt.term_id=9;

    Make a back up of your database first. Always a good idea before manually modifying it.

  3. JaneLitte
    Member
    Posted 4 years ago #

    Thank you very much. This worked perfect.

Topic Closed

This topic has been closed to new replies.

About this Topic