Notifications
Clear all

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

4 Posts
2 Users
0 Reactions
1,140 Views
Posts: 12
Customer
Topic starter
(@tennis2table)
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,


3 Replies
Astghik
Posts: 6561
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
Posts: 12
Customer
Topic starter
(@tennis2table)
Member
Joined: 5 years ago
Hello,


Reply
1 Reply
Astghik
Admin
(@astgh)
Joined: 8 years ago

Illustrious Member
Posts: 6561

@tennis2table 

Please provide us with a detailed list of the steps you’ve taken, so we can try to replicate the issue on our test websites for further investigation.

At the moment, we’re unable to reproduce the same issue on our end.


Reply
Share:
Scroll to top