[Solved] Which PHP files should be customized to add certain Tags automatically when someone adds a new topic?
Hi there
When someone adds a new topic, I need to save certain information (e.g. user's location which I can determine easily) along with the Tags.
Which PHP files should be customized to add certain Tags automatically when someone adds a new topic? These Tags will be in addition to the tags selected by a user.
Thanks.
To add, ideally I am looking for a solution which does not break with wpForo upgrades.
Thanks.
You should use the following code:
add_filter('wpforo_add_topic_data_filter', function($args){
$your_automated_tags = 'tag1,tag2';
$tags = (string) wpfval($args,'tags');
$args['tags'] = trim(trim($tags, ',') . ',' . trim($your_automated_tags, ','), ',');
return $args;
});
How to Easily Add Custom Code in WordPress (without Breaking Your Site).
Just change the red marked part in the code.
Please note in this case you should increase the value of the "Maximum Number of Tags per Topic" option. The option is located in the Dashboard > Forums > Settings > Topics & Posts tab. As far as, for example, if the value of the option is set 5 and the user adds 4 tags the second tag (tag2) will not be included. So please set the value of the option mentioned above more than 10.
In case you want to say thank you 😊
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.
That's great! As I need to add tags on fly (when users add a topic), where exactly, I mean which file will I put this code in please?
Thank you so much.
It should be added in the active theme functions.php file. I'd also suggest you read this article on How to Easily Add Custom Code in WordPress (without Breaking Your Site).
In case you want to say thank you 😊
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.
@sofy
- I normally avoid Plugins, so can I just paste it at the bottom of functions.php? Or where exactly in functions.php?
Thank you so much again!
In case you want to say thank you 😊
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.
@sofy Perfect. Sorry forgot to ask, when the user clicks on Add Topic button, how will I pass the Tags (tag1, tag2 etc.) as arguments to this function?
Thank you so much.
In case you want to say thank you 😊
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.
@sofy, true, but how and where will I pass those tag1, tag2, as arguments to your function when user clicks Add Topic submit button?
One of the tag is generated on fly using the Title of the topic, so I need a way to pass it to functions.php when user clicks on Add Topic submit button.
Thanks so much.
-
Adding tags
9 months ago
-
Change tags color
1 year ago
-
Delete tags
1 year ago
-
Serp Show only tag when search with "site:" all topics not showing but
2 years ago
-
Add Topic button on search results page
2 years ago
- 19 Forums
- 14.3 K Topics
- 71.7 K Posts
- 160 Online
- 6,448 Members