Wordpress-如何在wp-admin中提交表单后呈现选项页面?

时间:2019-06-11 13:40:12

标签: wordpress

我正在尝试创建一个自定义插件,该插件在添加的第一个选项页面上提交表单。

我想根据提交的数据从数据库中获取帖子,并在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_LIST_TABLE的适当wp-admin页面上显示此内容?

0 个答案:

没有答案