redirect - Submit New Post

admin2025-06-04  2

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";
    }
}

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";
    }
}
Share Improve this question edited Jan 24, 2019 at 7:21 Jacob Peattie 44.3k10 gold badges50 silver badges64 bronze badges asked Jan 24, 2019 at 3:07 Gary KwokGary Kwok 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 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;
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748979972a315346.html

最新回复(0)