首先,您是否检查了浏览器中的元框html?
您可能会发现上面的表单元素丢失了。这是因为不能有嵌套的表单元素:
<form>
<form>
</form>
</form>
所有元框都已位于表单元素内,因此不能在其中指定其他表单元素。
一种解决方案是使用Javascript AJAX函数提交添加的用户名:
Javascript部分:
jQuery.ajax({
url: \'http://yoursite.com/wp-admin/admin-ajax.php\',
dataType: \'json\',
//type:\'POST\',
data: {
\'action\':\'your_ajax\',
\'fn\': \'add_users_to_project\',
\'data\': data
},
success: function(results){
//console.log(results);
//display your added usernames
},// end of success
error: function(errorThrown){console.log(errorThrown);}
});// end of ajax
PHP部分:
class your_ajax{
//add actions and filters in constructor
function __construct(){
//admin or front end?
//add_action(\'wp_ajax_nopriv_your_ajax\', array( $this, \'ajax_function\' ) );
add_action(\'wp_ajax_your_ajax\', array( $this, \'ajax_function\' ) );
}
//handle ajax calls from
function ajax_function(){
// the first part is a SWTICHBOARD that fires specific functions
// according to the value of Query Var \'fn\'
//feel free to use this file for any wordpress ajax that needs to be done
switch($_REQUEST[\'fn\']){
case \'add_users_to_project\':
//$output = $_REQUEST[\'data\'];
$output = $this->add_users_to_project( $_REQUEST[\'data\'] );
break;
case \'delete_users_from_project\':
//$output = $_REQUEST[\'data\'];
$output = $this->delete_users_from_project( $_REQUEST[\'data\'] );
break;
default:
$output = \'No function specified, check your jQuery.ajax() call\';
break;
}
// Now, convert $output to JSON and echo it to the browser
// That way, we can recapture it with jQuery and run our success function
ob_clean();
$output=json_encode($output);
if( is_array( $output ) ):
print_r( $output );
else:
echo $output;
endif;
die();
}
function add_users_to_project( $data ){
//do whatever
return $response;
}
function delete_users_from_project( $data ){
//delete whatever
return $response;
}
}//end your_ajax class
$your_ajax = new your_ajax();
另一种选择是向
save_post
保存项目帖子时将触发的操作挂钩。然后简单地显示元框中的所有用户。
add_action( \'save_post\', \'your_save_function\' );
function your_save_function(){
//do stuff with global $post and $_POST
}
很抱歉回答得太长。。。希望您能找到适合您需求的解决方案。