0

I am trying to update my sql data through $wpdb, but can't... If anyone can help what's the real issue?

$updated_version = $wpdb->update('wp_visitors', array('views' => $updated), array( '%d' ));
1

You're missing your where statement. You need to tell wpdb which row it should be updating, otherwise you're looking to insert rather than update.

From the $wpdb::update Codex:

wpdb->update( string $table, array $data, array $where, array|string $format = null, array|string $where_format = null );
  • What should I need to the where statement? I've got only 1 column so as the row. – Musaf Hanif May 1 at 21:45
  • wp_visitors only has the column views? If that's the case, you probably want to use something other than a custom table. Take a look at options, cache, or transients, depending on your needs. – MikeNGarrett May 1 at 22:00
  • Sorry I can't understand, and please let me know if there is any possible solution of it? – Musaf Hanif May 1 at 22:59
  • Your use of a custom table doesn't make sense. – MikeNGarrett May 1 at 23:56
  • All i want is to get a value to update the Visitor Counter. – Musaf Hanif May 3 at 20:06

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.