Timeline for Get data from custom table and update relative post_meta based on meta_key
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 3, 2021 at 20:51 | vote | accept | Giacomo Gaglione | ||
Jul 3, 2021 at 20:39 | comment | added | shanebp | Since you found my answer useful, please upvote or accept it. wordpress.stackexchange.com/tour | |
Jul 3, 2021 at 20:37 | comment | added | shanebp |
For more than one column from a single row, use get_row . See developer.wordpress.org/reference/classes/wpdb/#select-a-row
|
|
Jul 3, 2021 at 18:17 | comment | added | Giacomo Gaglione |
Many thanks! I had to change custom_key_id = $post_sku into custom_key_id = '$post_sku' and now it works! Just and advice, if I have to retrieve vars form more than column, Do I need to duplicate $result = $wpdb->get_var( "SELECT custom_column1 FROM $customTable WHERE custom_key_id = $post_sku"); or there is a more concise way?
|
|
Jul 3, 2021 at 18:04 | comment | added | shanebp |
Edited to remove the undefined method error. You do not need LIMIT 1 when using get_var
|
|
Jul 3, 2021 at 18:03 | history | edited | shanebp | CC BY-SA 4.0 |
deleted 19 characters in body
|
Jul 3, 2021 at 17:54 | comment | added | Giacomo Gaglione |
Thank you @shanebp Unfortunately, it does not work. Regarding $meme_sku becoming post_sku is right (it is a typo). LIMIT 1 I have used it because I need to retrieve only the first row of the query. Anyway, I have used your exact code for the test but it gives me this error: fatal error: Uncaught Error: Call to undefined method WP_Post::the_post() . Also, I think in my there is a further error in my code: 'post_type' => 'products' should be 'post_type' => 'product' .
|
|
Jul 3, 2021 at 16:56 | history | answered | shanebp | CC BY-SA 4.0 |