Forum Replies Created
-
AuthorPosts
-
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
kabadabraMemberIf you’re saving to a CPT, be sure to add the following to the top of the form….
/* Title: Test Method: post Logged in: true Message: Data saved. */ /******* This section here is what you require ********/ // Where to save this form piklist('field', array( 'type' => 'hidden', 'scope' => 'post', 'field' => 'post_type', 'value' => 'custom_post_type_here' ) ); /***************/ piklist('field', array( 'type' => 'text', 'scope' => 'post_meta', 'field' => 'test', 'label' => __('Test'), )); // Rest of your form boxes.... piklist('field', array( 'type' => 'submit', 'field' => 'submit', 'value' => 'Submit' ));This defines which CPT to save to.
Hope this helps!
kabadabraMemberSure, http://codecanyon.net/item/userpro-user-profiles-with-social-login/5958681
Their main website: http://userproplugin.com/userpro/
kabadabraMemberThanks Steve, will give it a go
kabadabraMemberHaving the same problem on frontend forms. Is there fix/solution we could implement manually for now until the next release is available?
kabadabraMemberThanks Steve, much appreciated!
kabadabraMemberUpgraded to 0.9.9.7 and used the following post-to-post relate code and now it’s working 🙂
// Set relation piklist( 'field', array( 'type' => 'checkbox', 'field' => '_' . piklist::$prefix . 'relate_post', 'label' => __('Category'), 'choices' => piklist( get_posts( array( 'post_type' => 'contacts_categories', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ) ), array('ID', 'post_title') ), 'relate' => array( 'scope' => 'contacts_categories' ) ) );Topic can be closed / marked as resolved.
-
AuthorPosts