Viewing 4 reply threads
  • Author
    Posts
    • #10892
      guit4eva
      Participant

      Hello everyone 🙂

      How do you enable page attributes with a custom post type so that you can select the parent page?

      Also, is there a way to add a select field in a metabox that is populated with a specific custom post type (basically how the parent select works in Page Attributes, but limited to a post type)?

    • #10893
      Steve
      Keymaster

      @guit4eva– To answer both your questions:

      1) Pages are an “hierarchical” post type. You would set to true:
      `
      hierarchical => true

      register_post_type()

      2) I suggest you base your field off of this tutorial. It’s pulling menu items, but you can easily change to your post type: https://docs.piklist.com/tutorials/fields/display-menus-radio-checkbox-select-list/

      Let me know if you still have questions.

    • #10894
      guit4eva
      Participant

      Hi Steve,

      Thanks for your reply. I’ve set hierarchical to true, but only the menu order is showing (and not the parent dropdown). I’ve also followed the tutorial you linked, but am unable to get the custom post type pages to show up. This is what I have so far:

      $post_types['establishment-option'] = array(
        'labels' => piklist('post_type_labels', 'Establishment Options')
        , 'title' => __('Enter a new establishment option Title')
        , 'supports' => array(
            'title'
            , 'editor'
            , 'post-formats'
            , 'page-attributes'
            , 'thumbnail',
          )
        , 'public' => true
        , 'admin_body_class' => array(
            'custom-body-class',
        )
        , 'hierarchical' => true
        , 'has_archive' => true
        , 'rewrite' => array(
            'slug' => 'establishment-option',
        )
        , 'capability_type' => 'post'
        );

      and

      piklist('field', array(
        'type' => 'select'
        ,'field' => 'sidebar_left'
        ,'label' => 'Establishment'
        ,'value' => 'none'
        ,'choices' => array(
            '' => 'Select Establishment'
          )
          + piklist(get_posts(array(
            'post_type' => 'establishment_type'
            ,'hide_empty' => false
          ))
          ,array(
            'ID'
            ,'post_title'
          )
        )
      ));

      Can you see where I might be going wrong?

    • #10895
      guit4eva
      Participant

      Just a quick update:

      The “Parent” dropdown in Page Attributes is showing up now – I had to add more pages to that custom post type (I misunderstood how it works – I thought you could add a parent from any custom post type).

      I also made an error with this part: 'post_type' => 'establishment_type', it should just be 'post_type' => 'establishment'. All is working correctly now. Thanks so much for the help, it’s all making a lot more sense now!

    • #10896
      Steve
      Keymaster

      Nice job! Happy to help.

      If you are happy with the plugin and the support, and you have the time, we’d appreciate if you could leave us a review on WordPress.org. It really helps the project: https://wordpress.org/support/plugin/piklist/reviews/

Viewing 4 reply threads
  • You must be logged in to reply to this topic.