I am developing a plugin. Here I would like to redirect to all custom posts page after saving a custom post. My code is like below.
add_action( 'save_post', [ $this, 'save_meta_values' ] );
public function save_meta_values( $post_id )
{
//more code here
return $post_id; // I would like to direct here
}
How can I redirect to all post page like wp_redirect( admin_url( 'edit.php?post_type=news_info' ) );
?
May be I couldn't express myself properly.
I am developing a plugin. Here I would like to redirect to all custom posts page after saving a custom post. My code is like below.
add_action( 'save_post', [ $this, 'save_meta_values' ] );
public function save_meta_values( $post_id )
{
//more code here
return $post_id; // I would like to direct here
}
How can I redirect to all post page like wp_redirect( admin_url( 'edit.php?post_type=news_info' ) );
?
May be I couldn't express myself properly.
You can redirect this way:
add_action( 'save_post', 'save_meta_values' );
public function save_meta_values( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
// More code here ...
// Check if it's a custom post type names news_info
if ( 'news_info' === get_post_type( $post_id ) ) {
// Redirect to the CPT listing page
wp_redirect( admin_url( 'edit.php?post_type=product' ) );
exit;
}
return $post_id;
}