开发者

Wordpress update_post_meta does not update dynamic values

开发者 https://www.devze.com 2023-03-19 02:38 出处:网络
This is a little strange, I am using \"update_post_meta\" to update the custom fields in Wordpress. When I run update_post_meta($post_id, \'Test_Field\', \'Test Value\'); the custom field updates with

This is a little strange, I am using "update_post_meta" to update the custom fields in Wordpress. When I run update_post_meta($post_id, 'Test_Field', 'Test Value'); the custom field updates without a problem BUT when I use a string value it does not update:

$test_value = "Test";
 echo $test_value; // No problem here
 echo $post_id; // No problem here
 update_post_meta($post_id, 'Test_Fiel开发者_如何转开发d', $test_value);

Thanks very much in advance for your help

Stu


Try to cast variables with types. Try this:

update_post_meta( (int) $post_id, 'Test_Field', (string) $test_value );


Your first example used $post_id and solution $page_id. Was that a typo?


It might sound strange but, meta_key name must be identical to the input field name.

update_post_meta( $post_id, 'top_image', $_POST['top_image'] );

0

精彩评论

暂无评论...
验证码 换一张
取 消