save_post 'から呼び出された場合と呼ばれる場合、[save_post]から呼び出された場合、関数は異なる値を返します。

wordpress.stackexchange https://wordpress.stackexchange.com/questions/3526

  •  16-10-2019
  •  | 
  •  

質問

以下の「word_count」関数は、どこから呼び出されるかに応じて異なる値を返します。なんで?

add_action('save_post', 'my_custom_save', 10, 2);

function myPlugin($post)
{
    global $rockScore;
    global $text;
    $text = strip_tags($post->post_content);
    echo word_count($post); //returns "350"
}

function word_count($post)
{
    global $text;
    $word_count = explode(' ', $text);
    $word_count = count($word_count);
return $word_count;
}

function my_custom_save($postID, $post){
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $postID;
    }
    else
    {
        if($parent_id = wp_is_post_revision($postID))
        {
        $postID = $parent_id;
        }
        echo word_count($post);die; //still returns "1"
    }
}

register_activation_hook(__FILE__, 'myPlugin');
役に立ちましたか?

解決

おそらく改訂。 $> post_typeを確認してください。

ライセンス: CC-BY-SA帰属
所属していません wordpress.stackexchange
scroll top