Support » Developing with WordPress » Custom Post Type / page-parents

  • Resolved larethian

    (@larethian)


    Hey guys,

    I am having a little problem with my custom post type. I activated support for Page Parents and it was working quite well, but now (and I cant figure out why) some of the custom posts are not shown in the dropdown menu.

    I already checked the corresponding functions like wp_dropdown_pages and I can say that my post is hierarchical (otherwise the functionality wouldnt work at all) and has page capabilities. I assume that wordpress isnt passing all posts to the wp_dropdown_pages function to begin with, and while that may be okay, I cant figure out what the conditions are for a custom post to be included in the list of possible parents. This is how I initialized the custom post:

    /* Post Type registrieren */
      function kollektion_cpt() {
        $labels = array(
          'name'                => __( 'Kollektionen' ),
          'singular_name'       => __( 'Kollektion' ),
          'add_new'             => __( 'Kollektion hinzufügen' ),
          'add_new_item'        => __( 'Kollektion hinzufügen' ),
          'edit_item'           => __( 'Kollektion bearbeiten' ),
          'new_item'            => __( 'Kollektion hinzufügen' ),
          'view_item'           => __( 'Kollektion ansehen' ),
          'search_items'        => __( 'Kollektion suchen' ),
          'not_found'           => __( 'Keine Kollektion gefunden' ),
          'not_found_in_trash'  => __( 'Keine Kollektion im Papierkorb gefunden' ),
          'parent_item_colon'   => __( 'Elternkollektion' ),
          'all_items'           => __( 'Alle Kollektionen' )
        );
    
        $supports = array(
          'title',            //Kollektionsname
          'thumbnail',        //Thumbnail-Bild
          'excerpt',          //Auszug
          'editor',           //Haupttext - Kollektionsbeschreibung
          'page-attributes'   //Für die Hierarchie, damit man Kategorien anderen Kategorien zuordnen kann.
        );
    
        $args = array(
          'labels'          => $labels,
          'public'          => true,
          'supports'        => $supports,
          'hierarchical'    => true,
          'rewrite'         => true,
          'capability_type' => 'post'
        );
        register_post_type( 'kollektion', $args );
      }
      add_action( 'init', 'kollektion_cpt' );
Viewing 1 replies (of 1 total)
  • larethian

    (@larethian)

    Fixed it. I had to add a filter:

    add_filter('page_attributes_dropdown_pages_args', 'my_attributes_dropdown_pages_args', 1, 1);
    
    function my_attributes_dropdown_pages_args($dropdown_args) {
        $dropdown_args['post_status'] = array('publish','draft');
        return $dropdown_args;
    }

    This way drafts will be added to the list as well.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.