When updating non-public custom post type it says "Post updated. View Post"

I create a custom post type like this:add_action( 'init', function() {$args = array('description'

I create a custom post type like this:

add_action( 'init', function() {
    $args = array(
        'description'           => '',
        'public'                => false,
        'publicly_queryable'    => false,
        'show_ui'               => true,
        'show_in_rest'          => false,
        'rest_base'             => '',
        'has_archive'           => false,
        'show_in_menu'          => true,
        'exclude_from_search'   => false,
        'capability_type'       => 'post',
        'map_meta_cap'          => true,
        'hierarchical'          => false,
        'rewrite'               => array(
                                        'slug'              => 'job',
                                        'with_front'        => false
                                ),
        'query_var'             => true,
        'supports'              => array(
                                        'title'
                                    ),
        'label'                 => 'Jobs',
        'labels'                => array(
                                        'name'              => 'Jobs',
                                        'singular_name'     => 'Job',
                                        'menu_name'         => 'Jobs',
                                        'all_items'         => 'All Jobs',
                                        'add_new_item'      => 'Add New Job',
                                        'new_item'          => 'New Job',
                                        'edit_item'         => 'Edit Job',
                                        'view_item'         => 'View Job',
                                        'featured_image'    => 'Job Photo'
                                    ),
    );

    register_post_type( 'job', $args );
} );

You can see I have public and publicly_queryable set to false.

However, when I create a new post or update it, it says "Post updated. View post" where "View post" is a link to the post. This post is not public so it should not have a "View post" link. How can I stop it from adding this link to the updated message?

I create a custom post type like this:

add_action( 'init', function() {
    $args = array(
        'description'           => '',
        'public'                => false,
        'publicly_queryable'    => false,
        'show_ui'               => true,
        'show_in_rest'          => false,
        'rest_base'             => '',
        'has_archive'           => false,
        'show_in_menu'          => true,
        'exclude_from_search'   => false,
        'capability_type'       => 'post',
        'map_meta_cap'          => true,
        'hierarchical'          => false,
        'rewrite'               => array(
                                        'slug'              => 'job',
                                        'with_front'        => false
                                ),
        'query_var'             => true,
        'supports'              => array(
                                        'title'
                                    ),
        'label'                 => 'Jobs',
        'labels'                => array(
                                        'name'              => 'Jobs',
                                        'singular_name'     => 'Job',
                                        'menu_name'         => 'Jobs',
                                        'all_items'         => 'All Jobs',
                                        'add_new_item'      => 'Add New Job',
                                        'new_item'          => 'New Job',
                                        'edit_item'         => 'Edit Job',
                                        'view_item'         => 'View Job',
                                        'featured_image'    => 'Job Photo'
                                    ),
    );

    register_post_type( 'job', $args );
} );

You can see I have public and publicly_queryable set to false.

However, when I create a new post or update it, it says "Post updated. View post" where "View post" is a link to the post. This post is not public so it should not have a "View post" link. How can I stop it from adding this link to the updated message?

Share Improve this question asked Nov 21, 2019 at 11:30 GavinGavin 4347 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

to customise messages on edit page, you can use this filter :

add_filter("post_updated_messages", function ($messages) {

    $post_type = "job";

    if ($post_type === $GLOBALS["post_type"]) {

        $messages[$post_type] = [
            1 => "the object is updated",
            6 => "the object is created",
        ];

    }

    return $messages;

});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744983220a4604462.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信