Skip to:
Content
Pages
Categories
Search
Top
Bottom

Unable to Update Buddypress Database Tables via HTML Code


  • soopablogga
    Participant

    @soopablogga

    The goal is to find and replace thing1 with thing2 in the wp_bp_activity “content” table. This exact code works when I use it to change the standard wp_ tables, but does not when trying to update the buddypress bp_ prefixed tables. What am I doing wrong here??

    global $wpdb, $bp;
    $wpdb->query(
        $wpdb->prepare(
            "UPDATE {$wpdb->bp_activity}
            SET content = replace(content, %s, %s)",
            'thing1',
            'thing2'
            )
    );
Viewing 3 replies - 1 through 3 (of 3 total)

  • shanebp
    Moderator

    @shanebp

    Your query throws an error. Did you check your logs?
    And you don’t need theglobal $bp

    global $wpdb;
    $wpdb->query(
        $wpdb->prepare(
            "UPDATE {$wpdb->prefix}bp_activity
            SET content = replace(content, %s, %s)",
            'thing1',
            'thing2'
            )
    );

    soopablogga
    Participant

    @soopablogga

    @shanebp

    I don’t know how to check the logs, but will start researching that now. I tried copy and pasting the code you added and it broke the site unfortunately.

    Does the “>prefix” portion of that code need to be replaced by my site’s prefix? (it’s just the standard wp_.

    Thanks so much for your help!


    shanebp
    Moderator

    @shanebp

    The closing semicolon was not in the code section.
    I have edited my answer.
    If you don’t need to consider portability, then you can hardcode the prefix.
    UPDATE wp_bp_activity

    Learn how to debug in WP and you can answer most of your own questions.
    https://codex.wordpress.org/WP_DEBUG

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar