我创建了自定义帖子类型和自定义分类法。在分类中,我有一个用于排序顺序的字段。如果排序顺序留空,则不会显示产品类别。与排序顺序相关的代码是这个。
排序代码
<tr class="form-field">
<th scope="row" valign="top"><label for="cat_sort_order"><?php _e('Product Sort Order'); ?></label></th>
<td>
<input id="banner-url" name="term_meta[sort_order]" type="text" style="width: 100%;" value="<?php echo $term_meta['sort_order'] ? $term_meta['sort_order'] : ''; ?>" />
<span class="description"><?php _e(' '); ?></span>
</td>
</tr>
通话功能
$term = get_term($product, 'product-cat',array( 'parent' => 0,'hide_empty'=> true ));
if($counter==0){
$check=$term->parent;
$counter=1;
}
if($check==$term->parent)
{
$prod_meta = get_option("taxonomy_term_".$term->term_id);
echo $prod_meta['parent'];
$prod_meta['img'] = strstr($prod_meta['img'], '/wp-content');
$sorted_products[$prod_meta['sort_order']] = array(
'name' => $term->name,
'link' => get_term_link($product),
'term_id' => $term->term_id,
'img' => $prod_meta['img']);
}
else{
}
}
ksort($sorted_products);
只要特定类别的排序顺序留空,则不会显示。我希望排序顺序的默认值应该是 0。
WordPress 分类术语只能按 ASC 或 DESC 顺序排序。目前,自定义排序顺序是“开箱即用”的。