Support » Fixing WordPress » save costum taxonomies via costum meta boxes

  • Resolved IM_natascha


    First, this post follows this forum-discussion about disabling any modification of taxonomies where one solution was to remove the standard-taxonomy-input-boxes and insert a new, personal inputbox with a drop-down-menu (i only wanted “male” OR “female” to be selected as taxonomy-term).

    So, this is the code we are talking about:

    add_meta_box( $this->plugin_short.REGISTERED_POSTTYPE.'metas', __( 'Detailed Group Information'), array( &$this,'assoc_posttype_metabox_inner'), REGISTERED_POSTTYPE, 'normal', 'high');
    function assoc_posttype_metabox_inner ($post, $meta_box) {
      <select name="tax_input[<?= $taxonomy ?>]" id="tax-input-<?= $taxonomy ?>">
              <?php foreach(array(__('Male'), __('Female')) as $g): ?>
                <option <?php echo ($g == get_terms_to_edit( $post->ID, $taxonomy))?'selected':'' ?> ><?php echo $g; ?></option>
              <?php endforeach; ?>

    I get a normal dropbox with both “Male” and “Female”. I can save the costum post type. But I am stuck how I could ask the core functionalities to save my taxonomies.
    I tracked down tax_input and found this code of the definition $tax_input online. Each Element of tax_input[] should be adapted here.
    If I follow save_post I get to the function where it calls all registered hooks – apparently the function to save a post is called wp_insert_post(...). On line 2345 in my wp-includes/post.php I find following code:

    // new-style support for all custom taxonomies
    	if ( !empty($tax_input) ) {
    		foreach ( $tax_input as $taxonomy => $tags ) {
    			$taxonomy_obj = get_taxonomy($taxonomy);
    			if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
    				$tags = array_filter($tags);
    			if ( current_user_can($taxonomy_obj->cap->assign_terms) )
    				wp_set_post_terms( $post_ID, $tags, $taxonomy );

    Therefore I assumed, each element of $tax_input would be managed here to get inserted. But: there is no insert.

    Is the name-declaration of my dropdown correct or do I have to add additional attributes or special id-names to get this dropdown-menu recognized?
    What else am I missing?

Viewing 3 replies - 1 through 3 (of 3 total)
  • IM_natascha



    Seems like WordPress or my PHP installation does not support
    and therefore the array resulting from tax_input[<?= $taxonomy ?>] had a wrong associative key.



    You need shortags yes enabled in PHP config to allow for that to work but I think they are removing it from PHP5 anyway so most people recommend the long way !

    thank you xdesi!
    If they might remove it, it will be better to write the long way – just in case 😉

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘save costum taxonomies via costum meta boxes’ is closed to new replies.