Я пытаюсь создать собственный плагин, в котором отправляется форма на первой странице добавленной опции.
Я хочу получать посты из базы данных на основе предоставленных данных и показывать их на другой странице в wp-admin, чтобы пометить эти посты, чтобы добавить дополнительные данные к этим постам.
Проблема : При отправке формы для добавленного действия отображаются только значения $ _POST на сломанной странице вместо правильной страницы администратора.
Вопрос : как показать выбранные данные на правильной странице администратора?
function listposts_register_lists_page() {
//brings all posts at first time
add_options_page('Set Message in Selected Posts', 'Alert Messages', 'manage_options', 'listposts_plugin', 'listposts_lists_page'); //listposts_option_page
//Triggers upon Add New Button
add_options_page( 'Set Message in Selected Posts', '', 'manage_options', 'add-new-message', 'add_new_message_page');
}
add_action('admin_menu', 'listposts_register_lists_page');
форма
function add_new_message_page()
{
?>
<div class="wrap">
<h1>Set Alert Message</h1>
<form method='POST' action='<?php echo admin_url( 'admin-post.php' ); ?>'>
<input type='hidden' name='action' value='fetch_posts'/>
<?php wp_nonce_field( 'submitform', 'submitform_nonce' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Message</th>
<td><textarea id="listposts_option_name" name="listposts_option_name" value="<?php echo get_option('listposts_option_name'); ?>" ></textarea></td>
</tr>
<?php
// Excluded CPTs. You can expand the list.
$exclude_cpts = array(
'attachment'
);
// Builtin types needed.
$builtin = array(
'post',
'page',
// 'attachment'
);
// All CPTs.
$cpts = get_post_types( array(
'public' => true,
'_builtin' => false
) );
// remove Excluded CPTs from All CPTs.
foreach($exclude_cpts as $exclude_cpt)
unset($cpts[$exclude_cpt]);
// Merge Builtin types and 'important' CPTs to resulting array to use as argument.
$post_types = array_merge($builtin, $cpts);
//$post_types = get_post_types( $args, $output, $operator );
foreach ( $post_types as $post_type ) {
echo ' <tr valign="top">
<td><input type="checkbox" class="selectposttype" name="posttypes" value="'.$post_type.'" '.checked( $post_type, 1 ).' /></td>
<td scope="row"><label for="'.$post_type.'" >'.$post_type.'</label></td>
</tr>';
}
?>
</table>
<input type="submit" value="Send"/>
</form>
</div>
<?php
}
Функция обработки формы отправки
function show_posts(){
//This should be displayed on proper Option page instead of white page
var_dump($_POST);
}
Вот как это сделать на соответствующей странице wp-admin в WP_LIST_TABLE?