カスタムタクソノミーへの対応

フォーラム 要望と提案 カスタムタクソノミーへの対応

  • このトピックには2件の返信、2人の参加者があり、最後にandyにより13年、 5ヶ月前に更新されました。
3件の投稿を表示中 - 1 - 3件目 (全3件中)
  • 投稿者
    投稿
  • #50065
    andy
    参加者

    こんにちは。

    Welcartで商品を登録する際にカスタムタクソノミーで項目を分類しようと思うのですが、Welcartの商品登録画面でタクソノミーが階層なしの「投稿タグ」のような入力ボックスの場合は上手く登録できますが、階層がある「カテゴリ」のような入力ボックスの場合、ボックス内の中身が表示されずチェックをつけることが出来ません。

    pluginsusc-e-shopincludesmeta-boxes.phpのpost_categories_meta_box関数内のコメントアウトされている辺りを修正すれば対応出来ますが、もし可能であれば次回のWelcartのバージョンアップの際にカスタムタクソノミーに対応していただけるとありがたいです。

    ご検討よろしくお願いいたします。

    #60759
    nanbu
    キーマスター

    こんにちは。

    post_categories_meta_box() 関数を下記のものに置き換えてテストしてみていただけますでしょうか。問題なければ本体に組み込もうと思います。

    function post_categories_meta_box( $post, $box ) {
    $defaults = array('taxonomy' => 'category');
    if ( !isset($box['args']) || !is_array($box['args']) )
    $args = array();
    else
    $args = $box['args'];
    extract( wp_parse_args($args, $defaults), EXTR_SKIP );
    $tax = get_taxonomy($taxonomy);

    if( 'category' == $args['taxonomy'] ){
    ?>
    <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
    <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs">
    <li class="tabs"><a href="#<?php echo $taxonomy; ?>-items" tabindex="3"><?php _e( 'Item Category', 'usces' ); ?></a></li>
    <li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li>
    </ul>

    <div id="<?php echo $taxonomy; ?>-items" class="tabs-panel">
    <?php
    $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']';
    echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
    ?>
    <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear">
    <?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'descendants_and_self' => USCES_ITEM_CAT_PARENT_ID ) ) ?>
    </ul>
    </div>
    <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel" style="display: none;">
    <?php
    $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']';
    echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
    ?>
    <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear">
    <?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids ) ) ?>
    </ul>
    </div>
    </div>
    <?php

    }else{

    ?>
    <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
    <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs">
    <li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li>
    <li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
    </ul>

    <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel">
    <?php
    $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']';
    echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
    ?>
    <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear">
    <?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids ) ) ?>
    </ul>
    </div>
    <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;">
    <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" >
    <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?>
    </ul>
    </div>

    <?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
    <p><em><?php _e('You cannot modify this taxonomy.'); ?></em></p>
    <?php endif; ?>
    <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
    <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children">
    <h4>
    <a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3">
    <?php
    /* translators: %s: add new taxonomy label */
    printf( __( '+ %s' ), $tax->labels->add_new_item );
    ?>
    </a>
    </h4>
    <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child">
    <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php echo $tax->labels->add_new_item; ?></label>
    <input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->new_item_name ); ?>" tabindex="3" aria-required="true"/>
    <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent">
    <?php echo $tax->labels->parent_item_colon; ?>
    </label>
    <?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new'.$taxonomy.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;', 'tab_index' => 3 ) ); ?>
    <input type="button" id="<?php echo $taxonomy; ?>-add-submit" class="add:<?php echo $taxonomy ?>checklist:<?php echo $taxonomy ?>-add button category-add-sumbit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" tabindex="3" />
    <?php wp_nonce_field( 'add-'.$taxonomy, '_ajax_nonce-add-'.$taxonomy, false ); ?>
    <span id="<?php echo $taxonomy; ?>-ajax-response"></span>
    </p>
    </div>
    <?php endif; ?>
    </div>
    <?php

    }
    }

    #60760
    andy
    参加者

    nanbuさま。

    post_categories_meta_box()を早速そのコードに変更していくつかのタクソノミーでテストしたところ問題なく動いています。

    ご対応ありがとうございました!

3件の投稿を表示中 - 1 - 3件目 (全3件中)
  • このトピックに返信するにはログインが必要です。