BuddyPress Hashtags uses two custom database tables to store hashtag data.
Tables Overview
| Table | Purpose |
|---|---|
| wp_bpht_hashtags | Main hashtag storage |
| wp_bpht_hashtags_items | Hashtag-content relationships |
wp_bpht_hashtags
Stores hashtag information including name, type, and usage count.
Schema
CREATE TABLE wp_bpht_hashtags (
ht_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
ht_name varchar(128),
ht_type varchar(28),
ht_count bigint(20) UNSIGNED NULL DEFAULT '0',
ht_last_count TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (ht_id),
UNIQUE KEY ht_name_type (ht_name, ht_type),
KEY idx_ht_type (ht_type),
KEY idx_ht_count (ht_count),
KEY idx_ht_last_count (ht_last_count)
);
Columns
| Column | Type | Description |
|---|---|---|
| ht_id | bigint(20) UNSIGNED | Primary key, auto-increment |
| ht_name | varchar(128) | Hashtag name without # |
| ht_type | varchar(28) | Content type identifier |
| ht_count | bigint(20) UNSIGNED | Total usage count |
| ht_last_count | TIMESTAMP | Last update timestamp |
Content Types (ht_type)
| Value | Description |
|---|---|
| buddypress | BuddyPress activities |
| activity | BuddyPress activities (legacy) |
| bbpress | bbPress forums |
| post | WordPress posts |
| page | WordPress pages |
| profile | User profile content |
wp_bpht_hashtags_items
Links hashtags to content items and tracks user follows.
Schema
CREATE TABLE wp_bpht_hashtags_items (
id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
user_id bigint(20),
item_id bigint(20) UNSIGNED NULL DEFAULT '0',
type varchar(255),
hashtag_items varchar(255),
created_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY idx_user_id (user_id),
KEY idx_item_id (item_id),
KEY idx_type (type),
KEY idx_hashtag_items (hashtag_items)
);
Columns
| Column | Type | Description |
|---|---|---|
| id | int(11) UNSIGNED | Primary key, auto-increment |
| user_id | bigint(20) | WordPress user ID |
| item_id | bigint(20) UNSIGNED | Activity/post/topic ID |
| type | varchar(255) | Content type |
| hashtag_items | varchar(255) | Hashtag name |
| created_date | TIMESTAMP | Creation timestamp |
Common Queries
Get Top Hashtags
global $wpdb;
$table = $wpdb->prefix . 'bpht_hashtags';
$hashtags = $wpdb->get_results( $wpdb->prepare(
"SELECT ht_name, ht_count
FROM {$table}
WHERE ht_type = %s
ORDER BY ht_count DESC
LIMIT %d",
'buddypress',
20
) );
Get User’s Followed Hashtags
global $wpdb;
$table = $wpdb->prefix . 'bpht_hashtags_items';
$followed = $wpdb->get_results( $wpdb->prepare(
"SELECT DISTINCT hashtag_items
FROM {$table}
WHERE user_id = %d AND type = 'follow'",
get_current_user_id()
) );
Backup Considerations
When backing up the site, ensure these tables are included:
- wp_bpht_hashtags
- wp_bpht_hashtags_items
Standard WordPress backup plugins should capture these automatically as they use the standard $wpdb->prefix.
