September 15, 2020 at 12:43 pm #10892
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)?
September 15, 2020 at 6:56 pm #10893SteveKeymaster
@guit4eva– To answer both your questions:
1) Pages are an “hierarchical” post type. You would set to true:
hierarchical => true
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.
September 16, 2020 at 1:55 am #10894
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' );
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?
September 16, 2020 at 2:49 am #10895
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!
September 16, 2020 at 7:30 am #10896SteveKeymaster
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/
- You must be logged in to reply to this topic.