【问题标题】:Wordpress Custom_post slug и hurlWordpress Custom_post slug 和 hurl
【发布时间】:2021-05-19 17:28:12
【问题描述】:

有一个问题我几天都无法解决。所有搜索都归结为同一件事...

问题如下:
为了方便填写站点结构,需要to create a new post type,这个充满了在url中加了一个custom_post_slug,我想得到摆脱。

需要在以下类型的网站上保存投掷的结构:

site.com/类别/post_name
site.com/category/category_child/post_name

由于新的帖子类型,无论怎么说,结果都是这样:

site.com/custom_post_slug/post_name

我已经做过的事情:
大多数建议都不能解决问题,例如,replace slug with '/' - 它只会从 url 中删除 slug。

在创建新的帖子类型register_post_type () 时建议使用值rewrite => slug 指定%category%,这解决了我的问题,但之后新帖子类型get 404 的所有帖子,我不'不明白下一步该做什么。

添加一些代码:

function cptui_register_my_cpts_addresses() {
    /**
     * Post Type: Addresses.
     */
    $labels = [
        "name" => __( __("Addresses",'cnm_theme'), "custom-post-type-ui" ),
        "singular_name" => __( __("Addresses",'cnm_theme'), "custom-post-type-ui" ),
    ];
    $args = [
        "label" => __( __("Addresses",'cnm_theme'), "custom-post-type-ui" ),
        "labels" => $labels,
        "description" => "",
        "public" => true,
        "publicly_queryable" => true,
        "show_ui" => true,
        "show_in_rest" => true,
        "rest_base" => "",
        "rest_controller_class" => "WP_REST_Posts_Controller",
        "has_archive" => false,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "delete_with_user" => false,
        "exclude_from_search" => false,
        "capability_type" => "post",
        "map_meta_cap" => true,
        "hierarchical" => true,
        "rewrite" => [ "slug" => '%category%','with_front' => false ],
        // "rewrite" => false,
        "query_var" => true,
        "supports" => [ "title", "editor", "thumbnail", "excerpt", "trackbacks", "custom-fields", "comments", "revisions", "author", "page-attributes", "post-formats" ],
        "taxonomies" => [ "category", "post_tag" ],
    ];
    register_post_type( "addresses", $args );
}
add_action( 'init', 'cptui_register_my_cpts_addresses' );

【问题讨论】:

  • 您能提供给我们您的代码吗?不看也很难调试!!!!
  • @Ruvee 给你

标签: php wordpress url-rewriting wordpress-theming slug


【解决方案1】:

我决定离开 custom_slug,因为 url 的任何更改都不适合 WP 逻辑,所以我离开 custom_slug 但将其更改为一个字母,例如:

site.com**/a/category/category_child/**post_name

【讨论】:

    猜你喜欢
    • 2013-01-29
    • 1970-01-01
    • 2019-08-12
    • 2014-09-20
    • 2020-08-20
    • 2016-12-23
    • 1970-01-01
    • 2017-01-31
    • 2018-03-20
    相关资源
    最近更新 更多