wp admin - transition_post_status not working via Quick Edit

I am trying to use transition_post_status with custom post statuses to update user meta each time a post status is updat

I am trying to use transition_post_status with custom post statuses to update user meta each time a post status is updated. The following works when editing the post status in Edit Post Screen, but does not work when changing post status in Quick Edit in the admin view, which makes it difficult for the admin to change post statuses so that the change reflects in the user meta.

Is there something I might have missed?

function update_hit_rate( $new_status, $old_status, $post ) {
if ( $new_status != $old_status ) {
    global $post;

    $user_id = $post->post_author;

    $args = array(
    'author' => $user_id,
    'posts_per_page' => -1,
    'post_type' => 'betting_tip',
    'post_status' => array('hit','miss')
    );

    $posts = get_posts( $args );

    $hits = $misses = array();

    if ( ! empty( $posts ) ) :;
        foreach ( $posts as $post ) {
            switch ( $post->post_status ) {
                case 'hit':
                    $hits[] = $post;
                    break;
                case 'miss':
                    $misses[] = $post;
                    break;
                default:
                    break;
            }
        }
    endif;

    $hits = count($hits);
    $misses = count($misses);
    $hit_rate = round($hits / ($hits + $misses) * 100);

    update_user_meta( $user_id, 'hit_rate', $hit_rate);
  }
}
add_action( 'transition_post_status',  'update_hit_rate', 10, 3 );

EDIT: I am using the plugin Extended Post Status to add custom post statuses and status change options for the admin view. I also tried it with fully custom code, but the result is the same. User meta is updated from Edit Post screen, but from the Quick Edit menu it does nothing, even if the post status is changed.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745205873a4616589.html

相关推荐

  • wp admin - transition_post_status not working via Quick Edit

    I am trying to use transition_post_status with custom post statuses to update user meta each time a post status is updat

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信