I want to update a meta value with a specific meta key out of wordpress page. What I want is that, multiplying a meta value with a variable then write the result to another meta value.
for example;
$var=5
meta_key|meta_value
key-1 |10
key-2 |20
the meta_value for the key-1 = 100 (key-2 * $var). I have tried below code to retrieve key-1 but it returns nothing.
require_once("wp-load.php");
function wp_update_value( ) {
global $wpdb;
$mylink = $wpdb->get_results("
SELECT $wpdb->postmeta.meta_value
FROM $wpdb->postmeta
WHERE $wpdb->postmeta.meta_key = 'key-1'",
ARRAY_A);
$array = unserialize($mylink);
return $array;
}
How can I get two meta values by meta keys and update them for all posts?