Saving custom field value for new topic
Quote from Raki on December 17, 2018, 11:55 amHi there!
I’m trying to save a custom field value (color) for each new topic.
So far I set up the WP iris colorpicker below every topic form (I used the asgarosforum_editor_custom_content_bottom hook for that). But now I need some help saving this field and getting the data. While searching I stumbled upon the asgarosforum_after_add_topic_submit hook, but I got the feeling that this hook is too late.
Is there a hook I’m missing? Or is there another approach I could try? 🙂
Thanks!
Hi there!
I’m trying to save a custom field value (color) for each new topic.
So far I set up the WP iris colorpicker below every topic form (I used the asgarosforum_editor_custom_content_bottom hook for that). But now I need some help saving this field and getting the data. While searching I stumbled upon the asgarosforum_after_add_topic_submit hook, but I got the feeling that this hook is too late.
Is there a hook I’m missing? Or is there another approach I could try? 🙂
Thanks!
Quote from Asgaros on December 17, 2018, 12:32 pmHello @raki
The asgarosforum_after_add_topic_submit hook should be the correct one. Here is an example:
function save_color($post_id, $topic_id, $subject, $content, $link, $author_id) { if (!empty($_POST['forum_color'])) { // Save it somewhere. } } add_action('asgarosforum_after_add_topic_submit', 'save_color', 10, 6);The only thing you have to think about is where you want to save it. For example you can but it into an field in the WordPress options-table – accessible by an key based on the topic-id: asgarosforum_topic_1234_color.
Hello @raki
The asgarosforum_after_add_topic_submit hook should be the correct one. Here is an example:
function save_color($post_id, $topic_id, $subject, $content, $link, $author_id) { if (!empty($_POST['forum_color'])) { // Save it somewhere. } } add_action('asgarosforum_after_add_topic_submit', 'save_color', 10, 6);
The only thing you have to think about is where you want to save it. For example you can but it into an field in the WordPress options-table – accessible by an key based on the topic-id: asgarosforum_topic_1234_color.
Quote from Raki on December 17, 2018, 2:04 pmHi @asgaros
Thanks for your fast reply and your help! Gah, sometimes it’s just too easy 😉
One last question though: Is there a filter for editing the row-view? I’d like to add a custom attribute to the div.topic-element in the topic overview.
Hi @asgaros
Thanks for your fast reply and your help! Gah, sometimes it’s just too easy 😉
One last question though: Is there a filter for editing the row-view? I’d like to add a custom attribute to the div.topic-element in the topic overview.
Quote from Asgaros on December 17, 2018, 3:25 pmHello @raki
Yes, you can add custom columns to a topic-row with the asgarosforum_custom_topic_column hook. It uses one parameter: The ID of the topic.
Hello @raki
Yes, you can add custom columns to a topic-row with the asgarosforum_custom_topic_column hook. It uses one parameter: The ID of the topic.
Quote from Raki on December 17, 2018, 5:32 pmHi @asgaros
I’ve found that hook (and I’ll use that if there’s no other option) – I was just wondering if there is a hook for modifying the div.topic itself (instead of adding another column into it). 🙂
Hi @asgaros
I’ve found that hook (and I’ll use that if there’s no other option) – I was just wondering if there is a hook for modifying the div.topic itself (instead of adding another column into it). 🙂
Quote from jackfukushima on May 30, 2019, 9:04 pmQuote from Asgaros on December 17, 2018, 12:32 pmHello @raki
The asgarosforum_after_add_topic_submit hook should be the correct one. Here is an example:
function save_color($post_id, $topic_id, $subject, $content, $link, $author_id) { if (!empty($_POST['forum_color'])) { // Save it somewhere. } } add_action('asgarosforum_after_add_topic_submit', 'save_color', 10, 6);
- function save_color($post_id, $topic_id, $subject, $content, $link, $author_id) {
- if (!empty($_POST[‘forum_color’])) {
- // Save it somewhere.
- }
- }
- add_action(‘asgarosforum_after_add_topic_submit’, ‘save_color’, 10, 6);
function save_color($post_id, $topic_id, $subject, $content, $link, $author_id) { if (!empty($_POST['forum_color'])) { // Save it somewhere. } } add_action('asgarosforum_after_add_topic_submit', 'save_color', 10, 6);The only thing you have to think about is where you want to save it. For example you can but it into an field in the WordPress options-table – accessible by an key based on the topic-id: asgarosforum_topic_1234_color.
Hi @asgaros
I’ve saved the new data with add_option(), but how do I associate it with the topic-id? Thanks so much!
Quote from Asgaros on December 17, 2018, 12:32 pmHello @raki
The asgarosforum_after_add_topic_submit hook should be the correct one. Here is an example:
function save_color($post_id, $topic_id, $subject, $content, $link, $author_id) { if (!empty($_POST['forum_color'])) { // Save it somewhere. } } add_action('asgarosforum_after_add_topic_submit', 'save_color', 10, 6);
- function save_color($post_id, $topic_id, $subject, $content, $link, $author_id) {
- if (!empty($_POST[‘forum_color’])) {
- // Save it somewhere.
- }
- }
- add_action(‘asgarosforum_after_add_topic_submit’, ‘save_color’, 10, 6);
function save_color($post_id, $topic_id, $subject, $content, $link, $author_id) { if (!empty($_POST['forum_color'])) { // Save it somewhere. } } add_action('asgarosforum_after_add_topic_submit', 'save_color', 10, 6);The only thing you have to think about is where you want to save it. For example you can but it into an field in the WordPress options-table – accessible by an key based on the topic-id: asgarosforum_topic_1234_color.
Hi @asgaros
I’ve saved the new data with add_option(), but how do I associate it with the topic-id? Thanks so much!
Quote from Asgaros on May 30, 2019, 9:42 pmHello @jackfukushima
You can for example save the topic-ID with the data itself inside of an array:
$var = array(); $var['topic_id'] = 1337; $var['data'] = 'Your data ...';
Hello @jackfukushima
You can for example save the topic-ID with the data itself inside of an array:
$var = array(); $var['topic_id'] = 1337; $var['data'] = 'Your data ...';
Quote from jackfukushima on May 30, 2019, 11:10 pmHi @asgaros
Thanks for the reply! I was actually trying to save the option of a custom input field for that specific topic. Is there a way to do this?
Thanks so much!
Hi @asgaros
Thanks for the reply! I was actually trying to save the option of a custom input field for that specific topic. Is there a way to do this?
Thanks so much!
Quote from Asgaros on May 30, 2019, 11:20 pm@jackfukushima Of course, but it depends on your PHP-implementation. If you use custom database-tables for it you have to use a SQL-query. Otherwise you can save it inside of the options using an identifier based on the topic-ID and the custom input-name.
Here is an additional example:
function save_color($post_id, $topic_id, $subject, $content, $link, $author_id) { if (!empty($_POST['topic_color'])) { add_option('topic_color'.$topic_id, $_POST['topic_color']); } } add_action('asgarosforum_after_add_topic_submit', 'save_color', 10, 6);
@jackfukushima Of course, but it depends on your PHP-implementation. If you use custom database-tables for it you have to use a SQL-query. Otherwise you can save it inside of the options using an identifier based on the topic-ID and the custom input-name.
Here is an additional example:
function save_color($post_id, $topic_id, $subject, $content, $link, $author_id) { if (!empty($_POST['topic_color'])) { add_option('topic_color'.$topic_id, $_POST['topic_color']); } } add_action('asgarosforum_after_add_topic_submit', 'save_color', 10, 6);
Quote from jackfukushima on May 30, 2019, 11:27 pmHi @asgaros
This worked beautifully. Thank you so much!
Hi @asgaros
This worked beautifully. Thank you so much!