0

私のカスタム投稿タイプでは、ユーザーが投稿を保存したら、フィールドの1つの値を確認して更新する方法はありますか?挿入する値は投稿のIDによって異なるためsave_post、新しい投稿の場合に使用する必要があります。

4

1 に答える 1

1

はい、投稿を保存または更新した後、$_POSTまたはその後にすべてのデータを取得できますglobal $postusing save_post hook as you mentioned in your question

add_action( 'save_post', 'afterSavePost' );
function afterSavePost($pid)
{
    $postId=$pid; 
    // or
    global $post;
    $postId=$post->ID;
    $postTitle=$post->post_title; 
    // or
    $postId=$_POST['ID'];
    $postTitle=$_POST['post_title']; 
}

あなたは言及custom fieldしました、そしてその場合あなたは使うことができます

$yourCustomField=get_post_meta($postId, 'your_custom_field',true); // get a custom field

$yourCustomField="New value";
update_post_meta($postId, 'your_custom_field', $yourCustomField); // update a custom field
于 2012-04-19T22:16:37.517 に答える