Answer the question
In order to leave comments, you need to log in
What does this function do and how to add a condition?
Learn the basics of wordpress
add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) {
if ( "post" == $post->post_type && 'publish' === $new_status ) {
delete_transient( self::$cache_filed );
}
}, 10, 3 );
add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) {
if ( "post" == $post->post_type && 'publish' === $new_status || "event" == $post->post_type && 'publish' === $new_status ) {
delete_transient( self::$cache_filed );
}
}, 10, 3 );
Answer the question
In order to leave comments, you need to log in
You have interesting basics) You can shorten it a little by checking the current post_type in an array
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 );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question