admin管理员组文章数量:1287778
I am trying to add post-meta value and after this update query and after this get_post_meta value . but add_post_meta does not work .
<?php add_post_meta($post_id, 'Product_Year', trim( $_POST['Product_Year'])); ?>
<?php update_post_meta($post_id, 'Product_Year', trim( $_POST['Product_Year'])); ?>
echo $year=get_post_meta($post_id , 'Product_Year',true );
I am trying to add post-meta value and after this update query and after this get_post_meta value . but add_post_meta does not work .
<?php add_post_meta($post_id, 'Product_Year', trim( $_POST['Product_Year'])); ?>
<?php update_post_meta($post_id, 'Product_Year', trim( $_POST['Product_Year'])); ?>
echo $year=get_post_meta($post_id , 'Product_Year',true );
Share
Improve this question
asked Aug 2, 2017 at 6:19
sanjaysanjay
1035 bronze badges
1
|
2 Answers
Reset to default 1You dont need to use add_post_meta
and update_post_meta
for same meta_key.
You can simply use update_post_meta
function and this will
add if the meta_key does not exist and will update if meta_key exists.
Add last parameter, refer this https://codex.wordpress/Function_Reference/add_post_meta
add_post_meta($post_id, 'Product_Year', trim( $_POST['Product_Year']), true);
本文标签: custom fieldadd post meta value
版权声明:本文标题:custom field - add post meta value 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741326769a2372531.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$post_id
? – Jignesh Patel Commented Aug 2, 2017 at 8:57