- This topic has 8 replies, 3 voices, and was last updated 6 years, 8 months ago by
Steve.
-
AuthorPosts
-
-
June 1, 2014 at 8:31 pm #1777
mjenn123MemberI’ve created a custom post type and a custom taxonomy. I’m able to see the list of terms as a radio field on the custom post type using Piklist, but when I select one and save it, it does not seem to actually associate the cpt with the term. I’ve looked over my code dozens of times and tried several variations. I’m hoping I’m missing something obvious.
Any help would be welcome.
Here’s my plugin code (note that it’s not a theme).
Taxonomy definition:
add_filter('piklist_taxonomies', function( $taxonomies ){ $taxonomies[] = array( 'post_type' => 'sms_band' ,'name' => 'sms_shade' ,'show_admin_column' => true ,'hide_meta_box' => false ,'configuration' => array( 'hierarchical' => true ,'labels' => piklist('taxonomy_labels', 'Shade') ,'show_ui' => true ,'query_var' => false ) ); return $taxonomies; });Code in use to add two default terms
// Add 'Dark' and 'Light' default terms add_action('admin_init', function(){ $taxonomy = "sms_shade"; $term = "Dark Background [Light Text]"; $slug = "dark"; if ( !term_exists( $term, $taxonomy ) ){ wp_insert_term( $term, $taxonomy, array( 'slug' => $slug ) ); } $term = "Light Background [Dark Text]"; $slug = "light"; if ( !term_exists( $term, $taxonomy ) ){ wp_insert_term( $term, $taxonomy, array( 'slug' => $slug ) ); } });/parts/meta-boxes/band_shade.php
piklist('field', array( 'type' => 'radio' ,'field' => 'band_shade' ,'scope' => 'taxonomy' ,'label' => 'Shades' ,'choices' => piklist( get_terms('sms_shade', array( 'hide_empty' => false )) ,array( 'term_id' ,'name' )) )); -
June 1, 2014 at 9:59 pm #1778
mjenn123MemberIs it possible that I’m defining an incorrect scope? I can’t find what the options for that are other than ‘post_meta’ as explained here: http://piklist.com/user-guide/docs/fields/field-parameters/scope/
Is there further documentation somewhere that lists all the scope options available?
-
June 1, 2014 at 10:02 pm #1779
-
June 2, 2014 at 10:00 am #1783
SteveKeymaster@mjenn123– This is working for me. The only difference is that I associated
band_shadewith Post, since I don’t have the CPTsms_bandregistered.Also, do you have the necessary comment block at the top of:
/parts/meta-boxes/band_shade.php? Here is the doc on the comment block > -
June 2, 2014 at 5:28 pm #1784
mjenn123MemberHere’s the comment block I’m using.
/* Title: Band Options Post Type: sms_band */I must be doing something wrong. Probably some tiny little argument somewhere I’m missing.
When you say you “associated band_shade with post, did you do it like this:
/* Title: Band Options Post Type: post */ -
June 3, 2014 at 10:31 am #1791
SteveKeymaster@mjenn123– If you want, please zip up your code and email to [email protected]
-
June 1, 2015 at 7:17 am #3780
Quang AnhMemberHi Steve,
I have the same problems with taxonomy.
functions.php
add_filter('piklist_taxonomies', 'restaurant_cuisine'); function restaurant_cuisine($taxonomies) { $taxonomies[] = array( 'post_type' => 'restaurant' ,'name' => 'cuisine' ,'show_admin_column' => true ,'configuration' => array( 'hierarchical' => true ,'labels' => piklist('taxonomy_labels', 'Cuisines') ,'hide_meta_box' => true ,'show_ui' => true ,'query_var' => true ,'rewrite' => array( 'slug' => 'cuisine' ) ) ); return $taxonomies; }restaurant_metabox.php
piklist('field', array( 'type' => 'select' ,'scope' => 'taxonomy' ,'field' => 'restaurant_cuisine' ,'label' => 'Cuisine' ,'description' => 'Choose the Cuisine taxonomy.' ,'attributes' => array( 'multiple' => 'multiple' ) ,'choices' => $choices ));And I find a trick in that topics.
https://piklist.com/support/topic/warning-illegal-offset-type-in-isset-or-empty/When I removing scope it work. But the problem here is it do not effect the list taxonomies you choose. It store data in a different way not the ways you choose taxomony for your post and using with get_the_terms() function to get data. Can you help me find a solution.
Thanks
-
June 1, 2015 at 8:56 am #3781
Quang AnhMemberHi Steve,
I find your solution here: https://piklist.com/support/topic/my-field-is-not-saved/
Thanks./.
-
June 1, 2015 at 10:34 am #3782
SteveKeymasterGreat. Closing ticket
-
-
AuthorPosts
- The topic ‘Taxonomy field not saving on CPT’ is closed to new replies.