保存在我的自定义管理页面中并重定向到保存的对象

时间:2018-04-28 作者:dfrojas

我正在为我的插件构建管理页面,我在DB中保存得很好,但当我按下Save按钮时,页面会重新加载一个空表单。我想知道如何保存表单但进行重定向(我不知道这是否是重定向),但当页面重新加载时,显示最近保存的对象并在每个字段中显示相应的数据,例如,当我们写帖子时,首先post-new.php 但当我们保存WP时post.php?post=195&action=edit. 到目前为止,我有:

public function puzzle_manager(){
        global $wpdb;

        $file = file_get_contents(\'puzzle_manager.php\', FILE_USE_INCLUDE_PATH);
        if($file == false){
            echo \'file not found\';
        }
        else{
            echo $file;
        }

        $default = array(
        \'puzzle_title\' => \'\',
        \'image\' => \'\',
        \'rows\' => \'\',
        \'cols\' => \'\',
        \'timer\' => \'\',
        \'movements_counter\' => \'\',
        \'original_button\' => \'\',
        \'numbers_button\' => \'\',
        );

        $item = shortcode_atts( $default, $_REQUEST );
        $wpdb->insert( \'wp_puzzle\' , $item );
    }

1 个回复
SO网友:Manyang

你可以用$last_item = $wpdb->get_row( "SELECT * FROM $wpdb->wp_puzzle ORDER BY your_table_id DESC LIMIT 1", ARRAY_A ); 并在表格中手动输入每个项目

public function puzzle_manager(){
            global $wpdb;

            $file = file_get_contents(\'puzzle_manager.php\', FILE_USE_INCLUDE_PATH);
            if($file == false){
                echo \'file not found\';
            }
            else{
                echo $file;
            }

    $last_item = $wpdb->get_row( "SELECT * FROM $wpdb->wp_puzzle ORDER BY your_table_id DESC LIMIT 1", ARRAY_A  );

    if(!empty($last_item)){
    echo \'<pre>\';
    print_r_($last_item);
    //you must put manualy every $last_item value in your form, example $last_item[\'puzzle_title\'] in puzzle_title input
    echo \'</pre>\';
    }

            $default = array(
            \'puzzle_title\' => \'\',
            \'image\' => \'\',
            \'rows\' => \'\',
            \'cols\' => \'\',
            \'timer\' => \'\',
            \'movements_counter\' => \'\',
            \'original_button\' => \'\',
            \'numbers_button\' => \'\',
            );

            $item = shortcode_atts( $default, $_REQUEST );
            $wpdb->insert( \'wp_puzzle\' , $item );
        }

结束

相关推荐

how to read database fields

有人能解释一下如何读取wordpress数据库中的字母、数字和冒号吗?例如:a:1:{s:13:\"administrator\";b:1;} 在wp能力表中。谢谢