0

I'm building the admin page for my plugin, I'm saving well in the DB, but when I press the button Save the page is reloaded with an empty form. I'm looking how can I save the form but make a redirect (I don't know if this would be a redirect) but when the page is reloaded display the object recent saved and show the corresponding data in each field, for example, when we write a post, first we are in post-new.php but when we save WP take us to post.php?post=195&action=edit. Until now I have this:

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 );
    }
  • what is id of the wp_puzzle table? – Manyang Apr 28 '18 at 22:57
0

You can call them with $last_item = $wpdb->get_row( "SELECT * FROM $wpdb->wp_puzzle ORDER BY your_table_id DESC LIMIT 1", ARRAY_A ); and put manualy every item in your inputs at the form

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 );
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.