Custom taxonomy widget in WordPress admin area
-
OK, so I’ve searched high and low and I have no idea how to do this, so let’s see if anyone on here can.
I have a custom taxonomy set up on a custom post type and the box it uses is the same as categories, except I wanted to make it easily searchable using a filter script and then also allow the user to only select one and not multiple.
I managed to get the search/filter working and to get it to display on the sidebar under the custom post type in the admin area and then I managed to hide the old box, but now I can’t seem to get the term that is associated to a specific “post”. So none of them is returning as selected once you update the page.
Code below:
function my_client_box() { add_meta_box( 'clients_section', 'The title', 'clients_box', 'cars', 'side' ); } add_action( 'add_meta_boxes', 'my_client_box' ); function clients_box() { echo '<div class="clients_out"><input id="livefilter-input" type="text" value="" placeholder="Search names" autocomplete="off">'; echo '<div class="clients">'; echo '<ul id="clientlist">'; $terms = get_terms("client", 'orderby=name&order=ASC&hide_empty=0'); $count = count($terms); if ( $count > 0 ){ foreach ( $terms as $term ) { echo '<li><label><input type="radio" name="tax_input[client][]" value="' . $term->term_id . '"> <span>' . $term->name . '</span></label></li>'; } } echo '</ul>'; echo '</div>'; echo '</div>'; echo ' <script src="' . get_bloginfo('template_directory') . '/js/jquery.liveFilter.js"></script> <script> jQuery(function($){ $("#clientlist").liveFilter("#livefilter-input", "li", { filterChildSelector: "span" }); }); </script> '; }So when I print_r the $term var there doesn’t seem to be any indication about if the specific name should be checked or not… how would I go about doing this?
-
I don’t understand what you’re really trying to do. I see a list of terms filtered by what is input. Then what happens?
get_terms()returns all terms of a taxonomy. If you only want terms assigned to a particular post, usewp_get_post_terms()You say something about selection when updated. What’s selected? What is triggering an update? I don’t understand the sequence of events.You are looking for an indication if something should be checked. Why would one be checked and not another? What is being checked and for what?
Sorry for all the questions, I’d like to help you but I can’t unless I understand what you’re trying to do.
The topic ‘Custom taxonomy widget in WordPress admin area’ is closed to new replies.