Notifications
Clear all

Bug in wpForo Cross Posting — new topic created instead of linking to existing topic

2 Posts
2 Users
0 Reactions
12 Views
Posts: 11
Customer
Topic starter
(@besset-jerome)
Member
Joined: 5 years ago

Hello,

We’ve identified a bug in wpForo Cross Posting that causes a new topic to be created instead of linking a post to an existing topic when a topicid is manually entered in the post editor.

Symptom

  • Expected: when an existing topicid (e.g., 7955) is entered, the post should link to that topic.

  • Actual: a new topic is created (e.g., 8133), and the post links to this new topic.

Root cause 1 — Meta key mismatch (missing underscore)

The code reads the meta with an underscore before the prefix ('_' . $prefix . META_POST_TOPIC_ID) but writes it without the underscore ($prefix . META_POST_TOPIC_ID).
As a result, the stored topicid is never read back, the mapping appears “missing,” and a new topic is created.

Minimal fix (examples):

 
// BEFORE (write without underscore) ❌
update_post_meta($postID$prefix . wpForoCrossPostingOptions::META_POST_TOPIC_ID$topicID);

 

// AFTER (consistent with reads) ✅
update_post_meta($postID, '_' . $prefix . wpForoCrossPostingOptions::META_POST_TOPIC_ID, $topicID);

Apply similarly to the other related keys (forum/post):

 
update_post_meta($postID'_' . $prefix . wpForoCrossPostingOptions::META_POST_FORUM_ID$forumID);
update_post_meta($postID'_' . $prefix . wpForoCrossPostingOptions::META_POST_POST_ID$firstPostID);

Root cause 2 — User-entered topicid is overwritten by empty meta

In the save routine, the topicid from the form is read, but then it’s overwritten by the meta value (which is empty on the first link), forcing the “create topic” branch.

Logical fix (honor the user-entered value):

 
// After retrieving $topicID from $args:
if (!empty($topicID)) {
$topic = WPF()->topic->get_topic((int)$topicID);
if ($topic) {
// Persist immediately to the correct meta key (with underscore)
update_post_meta($postID'_' . $prefix . wpForoCrossPostingOptions::META_POST_TOPIC_ID, (int)$topicID);
update_post_meta($postID'_' . $prefix . wpForoCrossPostingOptions::META_POST_FORUM_ID, (int)$topic['forumid']);
}
}

 

// Then read from meta (now set)
$topicID = get_post_meta($postID, '_' . $prefix . wpForoCrossPostingOptions::META_POST_TOPIC_ID, true);
$topic = WPF()->topic->get_topic($topicID);

Outcome

  • Read/write use the same meta key, so the existing topicid is recognized.

  • The user-entered topicid is respected, preventing duplicate topics.

I can provide a precise patch/diff against your file if helpful.

Many thanks in advance!

Best regards,


1 Reply
Astghik
Posts: 6539
Admin
(@astgh)
Illustrious Member
Joined: 8 years ago

Please update the addon to the latest version, delete all kinds of caches and check again.

The issue should be solved 


Reply
Share:
Scroll to top