admin管理员组文章数量:1336699
Referring to post "adding-custom-fields-bbpress-topic-form" with link /, I want to add custom fields to bbpress reply form accordingly. I only altered several key words from "topic" to "reply". And I also tested more hooks to trigger the function. However, I could not show the related field after testing a test reply. Here is the code:
add_action ( 'bbp_theme_before_reply_form_content', 'bbp_extra_fields');
function bbp_extra_fields() {
$value = get_post_meta( bbp_get_reply_id(), 'bbp_extra_field1', true);
echo '<label for="bbp_extra_field1">Extra Field 1</label><br>';
echo "<input type='text' name='bbp_extra_field1' value='".$value."'>";
$value = get_post_meta( bbp_get_reply_id(), 'bbp_extra_field2', true);
echo '<label for="bbp_extra_field1">Extra Field 2</label><br>';
echo "<input type='text' name='bbp_extra_field2' value='".$value."'>";
}
// I can find the fields added (two input boxes)
add_action ( 'bbp_new_reply', 'bbp_save_extra_fields', 10, 1 );
add_action ( 'bbp_edit_reply', 'bbp_save_extra_fields', 10, 1 );
add_action ( 'save_post', 'bbp_save_extra_fields', 10, 1 );
function bbp_save_extra_fields($reply_id=0) {
if (isset($_POST) && $_POST['bbp_extra_field1']!='')
update_post_meta( $reply_id, 'bbp_extra_field1', $_POST['bbp_extra_field1'] );
if (isset($_POST) && $_POST['bbp_extra_field1']!='')
update_post_meta( $reply_id, 'bbp_extra_field1', $_POST['bbp_extra_field2'] );
}
//here I am not sure which hook should be used accordingly, but all four hooks do not work
add_action('bbp_template_before_replies_loop', 'bbp_show_extra_fields');
add_action('bbp_new_reply', 'bbp_show_extra_fields');
add_action('bbp_edit_reply', 'bbp_show_extra_fields');
add_action('save_post', 'bbp_show_extra_fields');
function bbp_show_extra_fields() {
$reply_id = bbp_get_reply_id();
$value1 = get_post_meta( $reply_id, 'bbp_extra_field1', true);
$value2 = get_post_meta( $reply_id, 'bbp_extra_field2', true);
//finally I can not find any extra fields information after I sent the reply
echo "Field 1: ".$value1."<br>";
echo "Field 2: ".$value2."<br>";
}
Please kindly give suggestion. Thanks!
Referring to post "adding-custom-fields-bbpress-topic-form" with link https://wp-dreams/articles/2013/06/adding-custom-fields-bbpress-topic-form/, I want to add custom fields to bbpress reply form accordingly. I only altered several key words from "topic" to "reply". And I also tested more hooks to trigger the function. However, I could not show the related field after testing a test reply. Here is the code:
add_action ( 'bbp_theme_before_reply_form_content', 'bbp_extra_fields');
function bbp_extra_fields() {
$value = get_post_meta( bbp_get_reply_id(), 'bbp_extra_field1', true);
echo '<label for="bbp_extra_field1">Extra Field 1</label><br>';
echo "<input type='text' name='bbp_extra_field1' value='".$value."'>";
$value = get_post_meta( bbp_get_reply_id(), 'bbp_extra_field2', true);
echo '<label for="bbp_extra_field1">Extra Field 2</label><br>';
echo "<input type='text' name='bbp_extra_field2' value='".$value."'>";
}
// I can find the fields added (two input boxes)
add_action ( 'bbp_new_reply', 'bbp_save_extra_fields', 10, 1 );
add_action ( 'bbp_edit_reply', 'bbp_save_extra_fields', 10, 1 );
add_action ( 'save_post', 'bbp_save_extra_fields', 10, 1 );
function bbp_save_extra_fields($reply_id=0) {
if (isset($_POST) && $_POST['bbp_extra_field1']!='')
update_post_meta( $reply_id, 'bbp_extra_field1', $_POST['bbp_extra_field1'] );
if (isset($_POST) && $_POST['bbp_extra_field1']!='')
update_post_meta( $reply_id, 'bbp_extra_field1', $_POST['bbp_extra_field2'] );
}
//here I am not sure which hook should be used accordingly, but all four hooks do not work
add_action('bbp_template_before_replies_loop', 'bbp_show_extra_fields');
add_action('bbp_new_reply', 'bbp_show_extra_fields');
add_action('bbp_edit_reply', 'bbp_show_extra_fields');
add_action('save_post', 'bbp_show_extra_fields');
function bbp_show_extra_fields() {
$reply_id = bbp_get_reply_id();
$value1 = get_post_meta( $reply_id, 'bbp_extra_field1', true);
$value2 = get_post_meta( $reply_id, 'bbp_extra_field2', true);
//finally I can not find any extra fields information after I sent the reply
echo "Field 1: ".$value1."<br>";
echo "Field 2: ".$value2."<br>";
}
Please kindly give suggestion. Thanks!
Share Improve this question asked May 20, 2020 at 14:19 DanielDaniel 111 bronze badge1 Answer
Reset to default 0Referring to previous post https://bbpress/forums/topic/add-custom-text-fields-to-reply-form/ I found "bbp_theme_after_reply_content" may be used effectively.
本文标签: postsAdding custom fields to bbpress reply form
版权声明:本文标题:posts - Adding custom fields to bbpress reply form 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742413107a2470182.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论