Tagged: hide_meta_box, taxonomies
- This topic has 13 replies, 2 voices, and was last updated 1 year, 8 months ago by
Steve.
-
AuthorPosts
-
-
June 9, 2020 at 9:15 am #10683
guit4evaParticipantHello again,
I’m trying to get a custom taxonomy to show on a custom post type, but I can’t get it to display properly. This is my code so far:
$post_types['package'] = array( 'labels' => piklist('post_type_labels', 'Packages') , 'title' => __('Enter a new Package Title') , 'supports' => array( 'title' , 'editor' , 'post-formats' , 'thumbnail', ) , 'public' => true , 'admin_body_class' => array( 'custom-body-class', ) , 'has_archive' => true , 'rewrite' => array( 'slug' => 'package', ) , 'capability_type' => 'post' , 'hide_meta_box' => array( 'author', ), ); return $post_types; } add_filter('piklist_taxonomies', 'package_tax'); function package_type_tax($taxonomies) { $taxonomies[] = array( 'post_type' => 'package' ,'name' => 'package_type' ,'show_admin_column' => true ,'configuration' => array( 'hierarchical' => false ,'labels' => piklist('taxonomy_labels', 'Package Type') ,'hide_meta_box' => true ,'show_ui' => true ,'query_var' => true ,'rewrite' => array( 'slug' => 'package-type' ) ) ); return $taxonomies; }If anyone can tell me where I’m going wrong, I’d really appreciate that!
-
June 9, 2020 at 9:21 am #10684
SteveKeymasterYour function is
package_type_tax, but the filter is callingpackage_tax. They need to match. -
June 9, 2020 at 9:27 am #10685
guit4evaParticipantI don’t know what’s greater: the speed at which you replied or my embarrassment for such a silly mistake ha ha…
Thanks for that, however the issue still persists after correction:
add_filter('piklist_taxonomies', 'package_type_tax'); function package_type_tax($taxonomies) {Not sure what else I’m doing wrong?
-
June 9, 2020 at 9:38 am #10686
SteveKeymasterHa! Thank you.
So, your code works for me when I use the default
postcpt. Try changing'post_type' => 'package'to'post_type' => 'post'and see if that works. If so, there may be something going on with your cpt registration. -
June 9, 2020 at 10:10 am #10687
guit4evaParticipantDrats, no luck… I’ve tried
'post_type' => 'post', checked Screen Options, nothing is showing in my cpt or in the default posts screen. Really stumped on this one! -
June 9, 2020 at 10:11 am #10688
SteveKeymasterwhat file is this in? And what is the path?
add_filter('piklist_taxonomies', 'package_type_tax'); function package_type_tax($taxonomies) { ... -
June 9, 2020 at 10:17 am #10689
guit4evaParticipantIt’s in /wp-content/plugins/custom-pklist/custom.php. This is the full file:
<?php /** * Plugin Name: Custom Piklist Functions * Description: Custom Piklist Functions * Author: SS * Version: 0.1 * Plugin Type: Piklist */ add_filter('piklist_post_types', 'piklist_custom_post_types'); function piklist_custom_post_types($post_types) { $post_types['event'] = array( 'labels' => piklist('post_type_labels', 'Events') , 'title' => __('Enter a new Event Title') // ,'menu_icon' => piklist('url', 'piklist') . '/parts/img/piklist-menu-icon.svg' // ,'page_icon' => piklist('url', 'piklist') . '/parts/img/piklist-page-icon-32.png' , 'supports' => array( 'title' , 'editor' , 'post-formats' , 'thumbnail', ) , 'public' => true , 'admin_body_class' => array( 'custom-body-class', ) , 'has_archive' => true , 'rewrite' => array( 'slug' => 'event', ) , 'capability_type' => 'post' // ,'edit_columns' => array( // 'title' => __('Demo') // ,'author' => __('Assigned to') // ) , 'hide_meta_box' => array( 'author', ), // ,'status' => array( // 'new' => array( // 'label' => 'New' // ,'public' => false // ) // ,'pending' => array( // 'label' => 'Pending Review' // ,'public' => false // ) // ,'demo' => array( // 'label' => 'Demo' // ,'public' => true // ,'exclude_from_search' => true // ,'show_in_admin_all_list' => true // ,'show_in_admin_status_list' => true // ) // ,'lock' => array( // 'label' => 'Lock' // ,'public' => true // ) // ) ); $post_types['package'] = array( 'labels' => piklist('post_type_labels', 'Packages') , 'title' => __('Enter a new Package Title') // ,'menu_icon' => piklist('url', 'piklist') . '/parts/img/piklist-menu-icon.svg' // ,'page_icon' => piklist('url', 'piklist') . '/parts/img/piklist-page-icon-32.png' , 'supports' => array( 'title' , 'editor' , 'post-formats' , 'thumbnail', ) , 'public' => true , 'admin_body_class' => array( 'custom-body-class', ) , 'has_archive' => true , 'rewrite' => array( 'slug' => 'package', ) , 'capability_type' => 'post' // ,'edit_columns' => array( // 'title' => __('Demo') // ,'author' => __('Assigned to') // ) , 'hide_meta_box' => array( 'author', ), // ,'status' => array( // 'new' => array( // 'label' => 'New' // ,'public' => false // ) // ,'pending' => array( // 'label' => 'Pending Review' // ,'public' => false // ) // ,'demo' => array( // 'label' => 'Demo' // ,'public' => true // ,'exclude_from_search' => true // ,'show_in_admin_all_list' => true // ,'show_in_admin_status_list' => true // ) // ,'lock' => array( // 'label' => 'Lock' // ,'public' => true // ) // ) ); return $post_types; } add_filter('piklist_taxonomies', 'package_type_tax'); function package_type_tax($taxonomies) { $taxonomies[] = array( 'post_type' => 'package' ,'name' => 'package_type' ,'show_admin_column' => true ,'configuration' => array( 'hierarchical' => false ,'labels' => piklist('taxonomy_labels', 'Package Type') ,'hide_meta_box' => true ,'show_ui' => true ,'query_var' => true ,'rewrite' => array( 'slug' => 'package-type' ) ) ); return $taxonomies; } -
June 9, 2020 at 10:35 am #10690
SteveKeymasterYour code works for me. I just placed it in my themes functions.php file: https://cloudup.com/cTlwcEicwDk
Make sure the plugin is activated.
-
June 9, 2020 at 1:52 pm #10691
guit4evaParticipantHi there Steve,
Thanks so much for your assistance. I discovered that I still needed to add the following to my parts file:
piklist('field', array( 'type' => 'select' ,'scope' => 'taxonomy' ,'field' => 'category' ,'label' => 'Categories' ,'description' => 'Terms will appear when they are added to this taxonomy.' ,'choices' => array( '' => 'Choose Term' ) + piklist(get_terms(array( 'taxonomy' => 'package_type' ,'hide_empty' => false )) ,array( 'term_id' ,'name' ) ) ));I was expecting the taxonomy section to show up in the right sidebar, which was what threw me off. It’s all working correctly now though 🙂
Thanks so much again for your help, it’s greatly appreciated!!
-
June 9, 2020 at 1:58 pm #10692
SteveKeymasterAh… The reason the metabox wasn’t showing up is because you have this Piklist parameter set
,'hide_meta_box' => true, which hides the meta box: https://piklist.github.io/docs/actions-filters/filters/piklist_taxonomies/#hide_meta_box -
June 9, 2020 at 2:26 pm #10693
guit4evaParticipantAh ok! 🙂 I see it’s showing up now in the sidebar – yesss!! What is the difference though with that, and then adding them as I did in the previous post (piklist(‘field’, array(‘type’ => ‘select’…)? I see if I add a duplicate taxonomy to the taxonomy field in the right sidebar, it doesn’t reflect in the taxonomy selection in the Piklist main section – although I’d think they’d be the same thing?…I’ll add a picture to explain what I mean:
Sorry if that’s a silly question, just trying to understand how this all fits together.
-
June 9, 2020 at 2:37 pm #10694
SteveKeymasterThe reason you would include
'hide_meta_box' => trueand create your own Piklist field for your taxonomy is if you didn’t want to use the default WordPress UI for your Taxonomy terms.You could use Chosen or Select2 to add some cool functionality.
Instead of checkboxes you could use Radio Buttons or a Select field.
Or maybe you want to group your taxonomy terms by their parent.
With Piklist you don’t have to limit yourself to the default WordPress UI. You can easily change it, and still save your data normally.
-
June 9, 2020 at 2:42 pm #10695
guit4evaParticipantAh, ok! Yes, I see how that could be very useful – especially if combining with something like Chosen. Piklist is really such a good addition to WordPress, really keen to learn about everything it can do 🙂
Thanks once again for your absolute stellar support!!!
Have a fantastic week 🙂
-
June 9, 2020 at 2:45 pm #10696
SteveKeymasterIf you have the time, feel free to leave a review on WordPress.org. It really helps the project. Thanks!
-
-
AuthorPosts
- The topic ‘Taxonomies not showing’ is closed to new replies.