admin管理员组文章数量:1404927
I'm using transition_post_status
to move a post into another post type based on the $new_status
, I had made two hooks but the second one always firing first even though the $new_status
is 'publish
'. I has try to change the priority but didn't work either, try to combine them into one hook also not working either...
//Move Group Queue CPT to Group Post Type
add_action( 'transition_post_status', 'groupqueue_to_groupcpt', 10, 3);
function groupqueue_to_groupcpt($new_status, $old_status, $post){
//Move to Group Post Type
if ('publish' === $new_status
&& 'groupq' === $post->post_type
)
wp_update_post(array(
'ID' => $post->ID,
'post_type' => 'group'
), true );
}
//Move Group Queue or Group CPT to Banned Post Type
add_action( 'transition_post_status', 'groupcpt_to_bannedcpt', 10, 5);
function groupcpt_to_bannedcpt($new_status, $old_status, $post){
if ( 'banned' === $new_status
&& 'groupq' === $post->post_type xor 'group' === $post->post_type
)
wp_update_post(array(
'ID' => $post->ID,
'post_type' => 'banned'
), true );
}
If I remove the groupcpt_to_bannedcpt
, the first one will be running fine. Is there a solution to this matter?
I'm using transition_post_status
to move a post into another post type based on the $new_status
, I had made two hooks but the second one always firing first even though the $new_status
is 'publish
'. I has try to change the priority but didn't work either, try to combine them into one hook also not working either...
//Move Group Queue CPT to Group Post Type
add_action( 'transition_post_status', 'groupqueue_to_groupcpt', 10, 3);
function groupqueue_to_groupcpt($new_status, $old_status, $post){
//Move to Group Post Type
if ('publish' === $new_status
&& 'groupq' === $post->post_type
)
wp_update_post(array(
'ID' => $post->ID,
'post_type' => 'group'
), true );
}
//Move Group Queue or Group CPT to Banned Post Type
add_action( 'transition_post_status', 'groupcpt_to_bannedcpt', 10, 5);
function groupcpt_to_bannedcpt($new_status, $old_status, $post){
if ( 'banned' === $new_status
&& 'groupq' === $post->post_type xor 'group' === $post->post_type
)
wp_update_post(array(
'ID' => $post->ID,
'post_type' => 'banned'
), true );
}
If I remove the groupcpt_to_bannedcpt
, the first one will be running fine. Is there a solution to this matter?
1 Answer
Reset to default 0You can user if..else
condition to combine both function into one hook.
add_action( 'transition_post_status', 'groupqueue_to_groupcpt_and_groupcpt_to_bannedcpt', 10, 3);
function groupqueue_to_groupcpt_and_groupcpt_to_bannedcpt($new_status, $old_status, $post){
//Move to Group Post Type
if ('publish' === $new_status && 'groupq' === $post->post_type )
{
wp_update_post(array(
'ID' => $post->ID,
'post_type' => 'group'
), true );
}
else if ( 'banned' === $new_status && ('groupq' === $post->post_type || 'group' === $post->post_type))
{
wp_update_post(array(
'ID' => $post->ID,
'post_type' => 'banned'
), true );
}
}
本文标签: phpSecond transitionpoststatus hook fired instead of the first
版权声明:本文标题:php - Second transition_post_status hook fired instead of the first 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744867084a2629407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论