最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Update wp_postmeta table based on 2 keys

programmeradmin0浏览0评论

I want to update the wp_postmeta table in the database based on 2 keys, is there a way to do that using any of the wordpress default functions. This is my DB query which is working fine:

$sql = "UPDATE wp_postmeta SET meta_value = meta_value + 1 WHERE post_id = 167788 AND meta_key = \"tie_views\"";

I want to update the wp_postmeta table in the database based on 2 keys, is there a way to do that using any of the wordpress default functions. This is my DB query which is working fine:

$sql = "UPDATE wp_postmeta SET meta_value = meta_value + 1 WHERE post_id = 167788 AND meta_key = \"tie_views\"";
Share Improve this question asked Aug 18, 2020 at 6:40 H_altH_alt 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Yes, there is.

These are some WP functions to get, add and update post meta values:

get_post_meta()

add_post_meta()

update_post_meta()

Your code could be:

$meta_value = (int) get_post_meta( $post->ID, 'meta_key', true );
update_post_meta( $post->ID, 'meta_key', $meta_value + 1 );
发布评论

评论列表(0)

  1. 暂无评论