Wordpress 当我只编辑自定义元字段时,save_post未启动

Wordpress 当我只编辑自定义元字段时,save_post未启动,wordpress,meta-boxes,Wordpress,Meta Boxes,几天前,我遇到了动作钩save_post,我喜欢利用它 我有一个自定义的post类型属性,其中包含与之关联的元字段。问题是,当我对帖子描述和标题进行更新时,只会激发save_post并执行我的功能,但如果我对与帖子相关联的元字段进行更改而不触及描述和标题,则不会激发save_post 我错过了什么 简单场景:仅当更新帖子标题和帖子描述时,才会触发save_post,但当我只编辑元字段而不触及描述和标题时,则不会触发save_post 有什么建议吗 My Functions.php代码,用于挂接s

几天前,我遇到了动作钩save_post,我喜欢利用它

我有一个自定义的post类型属性,其中包含与之关联的元字段。问题是,当我对帖子描述和标题进行更新时,只会激发save_post并执行我的功能,但如果我对与帖子相关联的元字段进行更改而不触及描述和标题,则不会激发save_post

我错过了什么

简单场景:仅当更新帖子标题和帖子描述时,才会触发save_post,但当我只编辑元字段而不触及描述和标题时,则不会触发save_post

有什么建议吗

My Functions.php代码,用于挂接save_post

function myplugin_save_postdata() {
alert('vijay','Event Fired!');
$postid=get_the_ID();

if ( 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $postid ) )
return;
} else {
if ( ! current_user_can( 'edit_post', $postid ) )
return;
}
$old_price = doubleval(get_post_meta($postid, 'REAL_HOMES_property_price', true));
$new_price = $_POST['REAL_HOMES_property_price'];
$vijay=doubleval(get_post_meta($postid, 'REAL_HOMES_property_old_price', true));
update_post_meta($postid,'REAL_HOMES_property_old_price',$old_price);
if($vijay !=''){
$sub_price = $new_price - $vijay;
$dev_price = intval(($sub_price * 100)/$vijay);
update_post_meta($postid, 'REAL_HOMES_property_price_development', $dev_price.'%');
}
}
add_action( 'save_post', 'myplugin_save_postdata' );

在更改元字段后,您可以尝试更新帖子上的按钮,这将触发保存帖子操作。

更新帖子元数据时不会触发保存帖子挂钩,但是在保存帖子元数据之前,会有一个过滤器可用:更新帖子元数据。这可以用来做同样的处理,并且在save_post期间可能会删除处理


很明显,我点击了更新按钮来更新帖子…但它没有发生
function prefix_add_custom_filter_for_postmeta_update() {
    add_filter( 'update_user_metadata', 'myplugin_update_foo', 10, 5 );
}
add_action( 'init', 'prefix_add_custom_filter_for_postmeta_update' );


function prefix_custom_filter_for_postmeta_update( $null, $object_id, $meta_key, $meta_value, $prev_value ) {

    // check if this update is for the key we want.
    if ( 'REAL_HOMES_property_price' == $meta_key && empty( $meta_value ) ) {
        // do your processing of values and updating of other metakeys here.
        // processing....
    }

    return null; // this means: go on with the normal execution and save.

}