Answer the question
In order to leave comments, you need to log in
How to run transition_post_status?
Tell me, there is a transition_post_status function
, the execution of the function hangs on it.
add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) {
if ( in_array( $post->post_type, ['post', 'event'] ) && 'publish' === $new_status ) {
delete_transient( self::$cache_filed );
}
}, 10, 3 );
Answer the question
In order to leave comments, you need to log in
For the record save event, you can use a hook save_post
, example:
add_action( 'save_post', 'custom_save_post' );
function custom_save_post( $post_id ) {
// добавляем стартовое кол-во просмотров для всех публикуемых страниц
add_post_meta( $post_id, 'views', random_int(20, 50), true );
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question