我希望通过下拉选择列表自定义bbpress回复表单区域。我之前在bbpress上找不到任何报道类似案件的帖子。参考带有链接的帖子“从所选下拉列表保存元框数据”https://stackoverflow.com/questions/17755973/save-meta-box-data-from-selected-dropdown-list我为bbpress回复帖子条件准备了类似的代码,但未能实现目标。
add_action( \'bbp_theme_before_reply_form_content\', \'so_custom_meta_box\' );
//add_action( \'add_meta_boxes\', \'so_custom_meta_box\' );
function so_custom_meta_box($post){
add_meta_box(\'so_meta_box\', \'Custom Box\', \'custom_element_grid_class_meta_box\', $post->post_type, \'normal\' , \'high\');
}
add_action(\'bbp_theme_before_reply_content\', \'so_save_metabox\');
function so_save_metabox(){
global $post;
if(isset($_POST["custom_element_grid_class"])){
//UPDATE:
$meta_element_class = $_POST[\'custom_element_grid_class\'];
//END OF UPDATE
update_post_meta($reply_id, \'custom_element_grid_class_meta_box\', $meta_element_class);
//print_r($_POST);
}
}
function custom_element_grid_class_meta_box($post){
$reply_id = bbp_get_reply_id();
$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
?>
<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
}
谁能提供善意的帮助来解决这个问题?谢谢