Tagged: hierarchical, taxonomy, widget
- This topic has 3 replies, 2 voices, and was last updated 6 years, 5 months ago by
Steve.
-
AuthorPosts
-
-
August 24, 2015 at 4:38 am #4247
redywebsMemberHi, I’m new to Piklist and I’ve made a hierarchical taxonomy for a custom post type, but want editors to only be able to select child terms. Can this be done with default metabox created or do I have to make a custom one and how?
I’m also trying to create a shortcode or a widget to display on front-end a list of that taxonomy.
Here is what I have
$genreslabels = array( 'name' => __( 'Genres', 'redywebs' ), 'singular_name' => __( 'Genre', 'redywebs' ), 'search_items' => __( 'Search Genres', 'redywebs' ), 'all_items' => __( 'All Genres', 'redywebs' ), 'parent_item' => __( 'Parent Genre', 'redywebs' ), 'parent_item_colon' => __( 'Parent Genre:', 'redywebs' ), 'edit_item' => __( 'Edit Genre', 'redywebs' ), 'update_item' => __( 'Update Genre', 'redywebs' ), 'add_new_item' => __( 'Add New Genre', 'redywebs' ), 'new_item_name' => __( 'New Genre Name', 'redywebs' ), 'not_found' => __( 'No Genres found.', 'redywebs' ), 'menu_name' => __( 'Genres', 'redywebs' ), ); $taxonomies[] = array( 'post_type' => 'catalog' ,'name' => 'colections' ,'configuration' => array( 'hierarchical' => true ,'labels' => $genreslabels ,'show_ui' => true ,'query_var' => true ,'rewrite' => array( 'slug' => __('colection'), ) ,'show_admin_column' => true ,'comments' => false ) );And this code would show a checkbox list with parents disable, but I’m not sure how and where it should go to achieve what I want:
$parents = get_terms('colections', array('hide_empty' => false,'parent' => 0 )); foreach ($parents as $parent => $value) { piklist('field', array( 'type' => 'checkbox', 'scope' => 'taxonomy', 'field' => 'colections', 'label' => $value->name, 'choices' => piklist( get_terms('colections', array( 'hide_empty' => false, 'child_of' => $value->term_id )), array( 'term_id', 'name' ) ) )); }Could you please help me?
-
August 24, 2015 at 10:39 am #4248
SteveKeymaster@redywebs– Welcome to the Piklist community!
One of the best parts of Piklist is that it’s code-based, which allows you to do almost anything.
If you only want Editors (or above) to select child terms than you can wrap the field in a conditional statement:
if(current_user_can('edit_pages')) : $parents = get_terms('colections', array('hide_empty' => false,'parent' => 0 )); foreach ($parents as $parent => $value) { piklist('field', array( 'type' => 'checkbox', 'scope' => 'taxonomy', 'field' => 'colections', 'label' => $value->name, 'choices' => piklist( get_terms('colections', array( 'hide_empty' => false, 'child_of' => $value->term_id )), array( 'term_id', 'name' ) ) )); } endif;Let me know if that works for you.
-
August 24, 2015 at 12:50 pm #4250
redywebsMemberHi Steve, thanks for your quick replay and your time.
Sorry, I probably did not make myself clear enough (English is not my mother tongue). It is not a conditional statement I was after, I meant anyone editing the post. I have the first part of the code in my main plugin php file, but if I add the second part just after it, it does nothing. That’s why I asked. Should I make it a custom metabox, take it from there and put the whole thing in meta-boxes folder? What am I doing wrong?Next, I’d like to create a shortcode or a widget to display on front-end a list of that taxonomy. I have tried to follow all tutorials I’ve found, with no luck. Could you please give me some directions on how to do it?
Thanks again for your time and patience.
-
August 24, 2015 at 2:19 pm #4251
-
-
AuthorPosts
- You must be logged in to reply to this topic.