• Resolved jakesimpson

    (@jakesimpson)


    I am currently using this in a plugin that I am creating for work.

    global $wpdb;
    global $confirm;
    $wpdb->update(
            $wpdb->prefix . 'posts',
            array( 'post_password' => $confirm ), // Replace wpse with your password 
            array( 'post_type' => 'final_decisions_cpt' ), // Replace post with the custom post type
            array( '%s' ), 
            array( '%d' ) 
        );

    This code works and presets the password for me, however it is applying to all post types. I want it to be specific to my cpt only. Any thoughts?

    • This topic was modified 5 years, 5 months ago by Jan Dembowski. Reason: Fixed formatting
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi

    1. You dont need to concatenate $wpdb->prefix and ‘posts’. $wddb->posts gives you the posts table name

    2. The second format you are passing, “%d”, is telling the value is a digit, where it is a string. Replace it with %s. This might work.

    Thread Starter jakesimpson

    (@jakesimpson)

    Awesome! That worked, thanks so much!

    Thread Starter jakesimpson

    (@jakesimpson)

    Would you by chance be able to direct me in the way to also set a password reset time?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘$wpdb->update’ is closed to new replies.