我添加了一个显示内容的部分,它引用了以前的一篇带有链接的文章https://bbpress.org/forums/topic/add-custom-text-fields-to-reply-form/. 下面的代码可以提供选项供用户选择。但无法显示选择结果。我不确定选择结果是否正确添加到metabox中,因为我无法使用调试功能。另一个问题是,“字段1”被插入到以前的所有回复帖子中。有没有人能进一步提供帮助来解决这个问题
add_action( \'bbp_theme_before_reply_form_content\', \'so_additional_content\' );
function so_additional_content($post){
$reply_id = bbp_get_reply_id();
$meta_element_class = get_post_meta($reply_id, \'custom_element_grid_class\', true);
//$meta_element_class = get_post_meta($reply_id, \'custom_element_grid_class_meta_box\', true); //true ensures you get just one value instead of an array
?>
echo \'<label>Choose the size of the element : </label>
<select name="custom_element_grid_class" id="custom_element_grid_class">
<option value="normal" <?php selected( $meta_element_class, \'normal\' ); ?>>normal</option>
<option value="square" <?php selected( $meta_element_class, \'square\' ); ?>>square</option>
<option value="wide" <?php selected( $meta_element_class, \'wide\' ); ?>>wide</option>
<option value="tall" <?php selected( $meta_element_class, \'tall\' ); ?>>tall</option>
</select>\'
<?php
}
add_action(\'bbp_new_reply_post_extras\', \'so_save_metabox\');
function so_save_metabox(){
global $post;
if(isset($_POST["custom_element_grid_class"])) {
//check the capability: if ( !current_user_can( \'edit_post\', $post->ID )) return $post->ID;
$meta_element_class = $_POST[\'custom_element_grid_class\'];
//END OF UPDATE
update_post_meta($reply_id, \'custom_element_grid_class\', $meta_element_class);
//update_post_meta($reply_id, \'custom_element_grid_class_meta_box\', $meta_element_class);
//print_r($_POST);
}
}
add_action(\'bbp_theme_before_reply_content\', \'so_show_metabox\');
function so_show_metabox() {
$meta_element_class = get_post_meta($reply_id, \'custom_element_grid_class\', true);
//$meta_element_class = get_post_meta($reply_id, \'custom_element_grid_class_meta_box\', true);
// the problem is "Field 1" appear in every reply post
echo "Field 1: ".$meta_element_class."End of testing "."<br>";
}