每次我的客户端上传产品时都需要运行此查询,那么如何在Wordpress中运行此查询?我想把它绑定到functions.php
中的一个动作UPDATE wp_postmeta
JOIN wp_posts ON wp_posts.id = wp_postmeta.post_id
SET wp_postmeta.meta_value = 'no'
WHERE (wp_posts.post_title = '4x6' AND wp_postmeta.meta_key = '_virtual')
答案 0 :(得分:0)
在functions.php中添加此代码:
function on_product_publish( $new_status, $old_status, $post ) {
global $post;
if ( 'publish' !== $new_status or 'publish' === $old_status ) return;
$wpdb->query("UPDATE wp_postmeta
JOIN wp_posts ON wp_posts.id = wp_postmeta.post_id
SET wp_postmeta.meta_value = 'no'
WHERE (wp_posts.post_title = '4x6' AND wp_postmeta.meta_key = '_virtual')");
}
add_action( 'transition_post_status', 'on_product_publish', 10, 3 );