私のカスタム投稿タイプでは、ユーザーが投稿を保存したら、フィールドの1つの値を確認して更新する方法はありますか?挿入する値は投稿のIDによって異なるためsave_post
、新しい投稿の場合に使用する必要があります。
3936 次
1 に答える
1
はい、投稿を保存または更新した後、$_POST
またはその後にすべてのデータを取得できますglobal $post
using 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 に答える