Skip to Content
Frontlane Studio
All Snippets
Bash BuddyBoss July 15, 2025

BuddyBoss: Find and Replace Text in All Forum Posts

When you need to update a term, link, or any piece of text across all forum discussions, this script is a lifesaver. It leverages the powerful wp search-replace command but scopes it specifically to the forum post type.

BuddyBoss WordPress

When you need to update a term, link, or any piece of text across all forum discussions, this script is a lifesaver. It leverages the powerful wp search-replace command but scopes it specifically to the forum post type.

#!/bin/bash

# Usage: ./replace_forum_text.sh "Old Text" "New Text"

# Check if both old and new text are provided
if [ -z "$1" ] || [ -z "$2" ]; then
  echo "Usage: $0 \"<old_text>\" \"<new_text>\""
  exit 1
fi

OLD_TEXT=$1
NEW_TEXT=$2

echo "Searching for '$OLD_TEXT' and replacing with '$NEW_TEXT' in all forum posts and replies..."

# Run a dry run first to see what will be changed
wp search-replace "$OLD_TEXT" "$NEW_TEXT" wp_posts --post_type=topic,reply --dry-run

# Ask for confirmation before proceeding
read -p "Do you want to proceed with the replacement? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
  # Perform the actual replacement
  wp search-replace "$OLD_TEXT" "$NEW_TEXT" wp_posts --post_type=topic,reply
  echo "Replacement complete."
else
  echo "Operation cancelled."
fi

How to Use:

  1. Save it as replace_forum_text.sh.

  2. Make it executable: chmod +x replace_forum_text.sh.

  3. Execute with the text to find and the text to replace it with: ./replace_forum_text.sh “Old Product Name” “New Product Name”.