2017-11-15 15 views
0

こんにちはカスタムカテゴリフィールドの投稿をフィルタリングしたいと思います。私はカスタムフィールドを作成し、それは動作しています。WordPressカテゴリのカスタムフィールド

/* Custom Field for Categories. 
    ======================================== */ 

// Add new term page 
function my_taxonomy_add_meta_fields($taxonomy) { ?> 
    <div class="form-field term-group"> 
     <label for="show_category"> 
      <?php _e('Show Category', 'codilight-lite'); ?> <input type="checkbox" id="show_category" name="show_category" value="yes" /> 
     </label> 
    </div><?php 
} 
add_action('category_add_form_fields', 'my_taxonomy_add_meta_fields', 10, 2); 

// Edit term page 
function my_taxonomy_edit_meta_fields($term, $taxonomy) { 
    $show_category = get_term_meta($term->term_id, 'show_category', true); ?> 

    <tr class="form-field term-group-wrap"> 
     <th scope="row"> 
      <label for="show_category"><?php _e('Show Category', 'codilight-lite'); ?></label> 
     </th> 
     <td> 
      <input type="checkbox" id="show_category" name="show_category" value="yes" <?php echo ($show_category) ? checked($show_category, 'yes') : ''; ?>/> 
     </td> 
    </tr><?php 
} 
add_action('category_edit_form_fields', 'my_taxonomy_edit_meta_fields', 10, 2); 

// Save custom meta 
function my_taxonomy_save_taxonomy_meta($term_id, $tag_id) { 
    if (isset($_POST[ 'show_category' ])) { 
     update_term_meta($term_id, 'show_category', 'yes'); 
    } else { 
     update_term_meta($term_id, 'show_category', ''); 
    } 
} 
add_action('created_category', 'my_taxonomy_save_taxonomy_meta', 10, 2); 
add_action('edited_category', 'my_taxonomy_save_taxonomy_meta', 10, 2); 

ここで、カテゴリ選択ボックスが表示されている投稿をフィルタリングして、はいにします。私はこのようなクエリを試していますが、それは動作していません

私はフィールドのセクションでそれがまだ動作していない方法で試してみました。これをどうすれば解決できますか?

答えて

0

は、私は解決策

$seasons = get_categories(
    array(
     'orderby' => 'name', 
     'order'  => 'ASC', 
     'hide_empty' => '0', 
     'meta_query' => array(
      array(
       'key'  => 'show_category', 
       'value' => 'yes', 
       'compare' => '=', 
      ) 
     ) 
    ) 
); 
0

オプションをさらに調整する必要があると思います。具体的用語、分類、およびフィールド

+0

申し訳ありませんが見つかりましたが、私は理解していませんでした。何が調整できますか? – trikutin

+0

投稿をプルする配列の値 –