最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

hierarchical - Having hierarchies inside Wordpress custom post type

programmeradmin0浏览0评论

I am trying to create a custom post type called DondeAmigo that accepts hierarchical pages. Example: I create a page called 'lewis', whose URL becomes: /donde-amigo/lewis. Then, I create a page called 'home' that I want it to be under 'lewis'. The idea would be for the URL to be /donde-amigo/lewis/home .

I set hierarchical to true and I added 'page-attributes' inside 'supports'. But still, when I edit the new page, I do not see the 'Add parent page' option.

//WHERE IS OUR FRIEND?
    $labels = array(
    'name' => _x( 'DondeAmigo', 'post type general name' ),
        'singular_name' => _x( 'dondeamigo', 'post type singular name' ),
        'add_new' => _x( 'Añadir nueva', 'book' ),
        'add_new_item' => __( 'Añadir nueva página' ),
        'edit_item' => __( 'Editar página' ),
        'new_item' => __( 'Nueva página' ),
        'view_item' => __( 'Ver página' ),
        'search_items' => __( 'Buscar página' ),
        'not_found' =>  __( 'No se han encontrado página' ),
        'not_found_in_trash' => __( 'No se han encontrado páginas en la papelera' ),
        
        'parent_item_colon' => ''
    );
 
    // Creamos un array para $args
    $args = array( 'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'taxonomies' => array('dondeamigo'),
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => true,
        'menu_position' => null,
        'show_in_rest' => true,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields','page-attributes')
    );
    
    register_post_type( 'donde-amigo', $args );

I am trying to create a custom post type called DondeAmigo that accepts hierarchical pages. Example: I create a page called 'lewis', whose URL becomes: /donde-amigo/lewis. Then, I create a page called 'home' that I want it to be under 'lewis'. The idea would be for the URL to be /donde-amigo/lewis/home .

I set hierarchical to true and I added 'page-attributes' inside 'supports'. But still, when I edit the new page, I do not see the 'Add parent page' option.

//WHERE IS OUR FRIEND?
    $labels = array(
    'name' => _x( 'DondeAmigo', 'post type general name' ),
        'singular_name' => _x( 'dondeamigo', 'post type singular name' ),
        'add_new' => _x( 'Añadir nueva', 'book' ),
        'add_new_item' => __( 'Añadir nueva página' ),
        'edit_item' => __( 'Editar página' ),
        'new_item' => __( 'Nueva página' ),
        'view_item' => __( 'Ver página' ),
        'search_items' => __( 'Buscar página' ),
        'not_found' =>  __( 'No se han encontrado página' ),
        'not_found_in_trash' => __( 'No se han encontrado páginas en la papelera' ),
        
        'parent_item_colon' => ''
    );
 
    // Creamos un array para $args
    $args = array( 'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'taxonomies' => array('dondeamigo'),
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => true,
        'menu_position' => null,
        'show_in_rest' => true,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields','page-attributes')
    );
    
    register_post_type( 'donde-amigo', $args );

Share Improve this question asked Jan 9, 2021 at 12:10 Luis GaldoLuis Galdo 1012 bronze badges 3
  • Are there more than 1 pages - you can't have a parent until you have 2 pages? also, did you try 'capability_type' => 'page', – Q Studio Commented Jan 9, 2021 at 12:29
  • Yes, I already have 4 pages created, but when adding a new one, no option for it being the child of one of the others. – Luis Galdo Commented Jan 9, 2021 at 13:00
  • Also, I tried 'capability_type' => 'page' and nothing – Luis Galdo Commented Jan 9, 2021 at 13:02
Add a comment  | 

1 Answer 1

Reset to default 0

I discovered that if you press fast_edit before editing the page, there is an option to choose the superior page. While if you access edit this option is not present.

The reason might be a collision between plugins or between a plugin and WordPress.

发布评论

评论列表(0)

  1. 暂无评论