0

I'm the junior of wordpress and web designer, there is a stupid question would like to ask.

At the wordpress web site, when I create new post and submit. The page will fallback to edit post page. But I want it can redirect to this related post or page. How can I change this using coding or plugin?

I found the post-new.php for this, But I don't know how to make it achieve for my goal. Thanks.

if ( 'post' == $post_type ) {
    $parent_file = 'edit.php';
    $submenu_file = 'post-new.php';
} elseif ( 'attachment' == $post_type ) {
    if ( wp_redirect( admin_url( 'media-new.php' ) ) )
        exit;
} else {
    $submenu_file = "post-new.php?post_type=$post_type";
    if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true ) {
        $parent_file = $post_type_object->show_in_menu;
        // What if there isn't a post-new.php item for this post type?
        if ( ! isset( $_registered_pages[ get_plugin_page_hookname( "post-new.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) ) {
            if (    isset( $_registered_pages[ get_plugin_page_hookname( "edit.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) ) {
                // Fall back to edit.php for that post type, if it exists
                $submenu_file = "edit.php?post_type=$post_type";
            } else {
                // Otherwise, give up and highlight the parent
                $submenu_file = $parent_file;
            }           
        }
    } else {
        $parent_file = "edit.php?post_type=$post_type";
    }
}

1 Answer 1

0

You should take a look at the redirect_post_location filter

Here is a snippet:

add_filter( 'redirect_post_location', 'yourcustom_redirect_post_location' );
function yourcustom_redirect_post_location( $location, $post_id ) {

    if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ){
        return get_permalink( $post_id );
    }

    return $location;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.