Tagged: taxonomy forms
- This topic has 3 replies, 3 voices, and was last updated 6 years, 1 month ago by
kabadabra.
-
AuthorPosts
-
-
November 28, 2015 at 9:46 am #5141
spsenthilrajaMemberHi,
I have a CPT and custom taxonomy which works perfectly in admin panel but when I try to mock the same using forms, all the post and post_meta related fields are saved except scope taxonomy. please help.
Taxonomy Creation part
========================
$taxonomies[] = array(
‘post_type’ => ‘job’
, ‘name’ => ‘job_category’
, ‘show_admin_column’ => true
, ‘configuration’ => array(
‘hierarchical’ => false
, ‘labels’ => piklist(‘taxonomy_labels’, ‘Job Categories’)
, ‘show_ui’ => true
, ‘hide_meta_box’ => true
, ‘query_var’ => true
, ‘rewrite’ => array(
‘slug’ => ‘job-category’,
),
),
);
return $taxonomies;in forms/job-form.php
=====================
piklist(‘field’, array(
‘type’ => ‘select’
, ‘scope’ => ‘taxonomy’
, ‘field’ => ‘job_category’
, ‘label’ => ‘Category’
, ‘description’ => ‘Terms will appear when they are added to this taxonomy.’
, ‘choices’ => piklist(get_terms(‘job_category’, array(
‘hide_empty’ => false,
))
, array(
‘term_id’
, ‘name’,
)
),
));Please help us.
-
November 30, 2015 at 3:54 pm #5161
SteveKeymaster@spsenthilraja– Welcome to the Piklist community!
Congratulations, you’ve found a bug with the front-end forms. We’ll get it fixed in the next version of Piklist.
-
December 12, 2015 at 7:53 am #5307
kabadabraMemberHaving the same problem on frontend forms. Is there fix/solution we could implement manually for now until the next release is available?
-
December 14, 2015 at 8:29 am #5321
kabadabraMemberA bit messy but I managed to get it going with a bit of a work-around for the time being.
First I created a hidden field to temporarily store the category/taxonomy value
piklist( 'field', array( 'scope' => 'post_meta', 'type' => 'hidden', 'field' => 'category', 'label' => __('Category') ) );To get the taxonomy’s to display with a select dropdown where parents are disabled, I set the new select field’s name and id to that of the hidden field above.
<div class="form-group piklist-theme-field-container"> <div class="piklist-theme-label"> <label for="_post_meta[category]" class="piklist-field-part piklist-label piklist-label-position-before ">Category</label> </div> <select id="_post_meta_category_0" name="_post_meta[category]" class="ad-category form-control _post_meta_category piklist-field-element"> <?php foreach ($parents as $parent => $value) { echo '<option disabled="disabled" value="0">'.$value->name.'</option>'; $terms = get_terms( 'classifieds_categories', array( 'hide_empty' => false, 'parent' => $value->term_id ) ); foreach ($terms as $term) { echo '<option value="'.$term->term_id.'"> - '.$term->name.'</option>'; } } ?> </select> </div>With a “save_post” hook I then used the temporary stored category meta value to set the taxonomy terms
function custom_save_taxonomy( $post_id ) { $post = get_post( $post_id ); if($post->post_type != 'classifieds') return $post_id; $category = get_post_meta( $post_id, 'category', true ); wp_set_post_terms($post_id, array($category), 'classifieds_categories', true); $terms = wp_get_post_terms($post_id, 'classifieds_categories' ); foreach($terms as $term){ while($category != 0 && !has_term( $category, 'classifieds_categories', $post )){ // move upward until we get to 0 level terms wp_set_post_terms($post_id, array($category), 'classifieds_categories', true); $term = get_term($category, 'classifieds_categories'); } } return true; } add_action( 'save_post', 'custom_save_taxonomy' );Hope this helps someone, works for what I needed to do:
https://dl.dropboxusercontent.com/s/asew27emsuejmal/2015-12-14%20at%2014.27.jpg
-
-
AuthorPosts
- You must be logged in to reply to this topic.