自定义帖子类型另存为基本帖子

时间:2019-06-19 作者:J.BizMai

我为其他帖子类型定制了一个帖子类型过滤器。slug是一个串联"filters-" . $custom-post-type.

自定义帖子类型将正确显示在菜单中:

enter image description here

我的问题是,当我试图保存一个时,它是用post_type = post.我错过了什么?

这是我的PHP代码:

class SearchFilters
{


    public $post_type_slug;
    public $post_type_label_name;
    public $post_type_singular_name;

    public $current_plugin_domain;

    public function __construct( $post_type_slug, $post_type_label_name, $post_type_singular_name )
    {
        $this->current_plugin_domain = get_current_plugin_domain();

        $this->post_type_slug = $post_type_slug;
        $this->post_type_label_name = $post_type_label_name;
        $this->post_type_singular_name = $post_type_singular_name;
        $this->init();
    }

    private function init(){
        $filters_slug = "filters-" . $this->post_type_slug;
        $filters_args = [
            \'labels\' => array(
                \'name\'          => sprintf( __( "Filters - Search Form for %s", $this->current_plugin_domain  ), $this->post_type_label_name   ),
                \'singular_name\' => __( "Filter", $this->current_plugin_domain  ),
                \'menu_name\'          => __( "Filters", $this->current_plugin_domain  ),
                \'add_new_item\'          => sprintf( __( "Filters - Add New Search Form for %s", $this->current_plugin_domain  ), $this->post_type_singular_name  )
            ),
            \'description\' => __( "Filters to display search form on front end", $this->current_plugin_domain ),
            \'supports\' => array( \'title\' ),
            \'public\' => false,
            \'show_ui\' => true,
            \'show_in_menu\' => "edit.php?post_type=" . $this->post_type_slug,
            \'auto_save\' => false
        ];
        $result_filter = register_post_type(
            $filters_slug,
            $filters_args
        );
        if ( is_wp_error( $result_filter ) ) {
            wp_error_log( $result_filter->get_error_message(), "Filter Post type creation " . "[" . __CLASS__ . "]" );
        }

    }
}

2 个回复
SO网友:Milan Hirpara

请尝试以下代码:

class SearchFilters
{


    public $post_type_slug;
    public $post_type_label_name;
    public $post_type_singular_name;

    public $current_plugin_domain;

    public function __construct( $post_type_slug, $post_type_label_name, $post_type_singular_name )
    {
        $this->current_plugin_domain = get_current_plugin_domain();

        $this->post_type_slug = $post_type_slug;
        $this->post_type_label_name = $post_type_label_name;
        $this->post_type_singular_name = $post_type_singular_name;
        $this->init();
    }

    private function init(){
        $filters_slug = "filters-" . $this->post_type_slug;
        $filters_args = [
            \'labels\' => array(
                \'name\'          => sprintf( __( "Filters - Search Form for %s", $this->current_plugin_domain  ), $this->post_type_label_name   ),
                \'singular_name\' => __( "Filter", $this->current_plugin_domain  ),
                \'menu_name\'          => __( "Filters", $this->current_plugin_domain  ),
                \'add_new_item\'          => sprintf( __( "Filters - Add New Search Form for %s", $this->current_plugin_domain  ), $this->post_type_singular_name  )
            ),
            \'description\' => __( "Filters to display search form on front end", $this->current_plugin_domain ),
            \'supports\' => array( \'title\' ),
            \'public\' => false,
            \'show_ui\' => true,
            \'exclude_from_search\' => true,
            \'show_in_admin_bar\'   => false,
            \'show_in_nav_menus\'   => false,
            \'publicly_queryable\'  => false,
            \'query_var\'           => false,
            \'show_ui\' => true,
            \'menu_icon\' => \'dashicons-tag\',
            \'capability_type\' => \'post\',
            \'rewrite\' => array( \'slug\' => $this->post_type_slug),
            \'show_in_menu\' => "edit.php?post_type=" . $this->post_type_slug,
            \'auto_save\' => false
        ];
        $result_filter = register_post_type(
            $filters_slug,
            $filters_args
        );
        if ( is_wp_error( $result_filter ) ) {
            wp_error_log( $result_filter->get_error_message(), "Filter Post type creation " . "[" . __CLASS__ . "]" );
        }

    }
}

SO网友:J.BizMai

问题似乎是链接到我所做的jQuery脚本,以检查后期保存的内容。

我忘了:

$postForm.unbind(\'submit\');

相关推荐