1

My plan is to upsert values in a custom meta table with $wpdb->replace.

This is what I try:

$up_meta = $wpdb->replace(
    'spieldaten',
    array(
        'spiel_uid' => $uid,
        'dkey' => $prop,
        'dval' => $_POST[$prop]
    )
);

What I want to achieve:

  • spiel_uid and dkey is the primary key of my meta table (similar to wp_postmeta).
  • Update dval where dkey and spiel_uid have the given values
  • If there is no such row, just insert the complete record

How can $wpdb->replace know where I want to replace? $wpdb->update in contrast has a $where parameter.

Related information:

https://codex.wordpress.org/Class_Reference/wpdb#REPLACE_row https://codex.wordpress.org/Class_Reference/wpdb#UPDATE_rows

Your Answer

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

Browse other questions tagged or ask your own question.