$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>redirect - Submit New Post|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

redirect - Submit New Post

matteradmin11PV0评论

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far