按日期对标签排序

时间:2015-11-27 13:18:57

标签: php wordpress

我正在使用WordPress主题。这是我在那里用来在博客页面中显示标签的代码:

<div class="custom-category">
    <?php
      $post_tags_show_text = __('Tags', 'directory');

      $categories_list = get_the_term_list ( $cs_post_id, 'directory-tag', '<li>', '</li><li>', '</li>' );

      if ( isset($categories_list) ){ ?>
        <div class="cs-tags"> <!-- cs Tages Start -->
          <h5><?php echo esc_attr($post_tags_show_text);?></h5>
          <ul> <?php printf( __( '%1$s', 'directory'),$categories_list ); ?></ul>
        </div>
    <?php
     } ?>
    </div>

但它会按字母顺序自动排序。无论如何要调整它以便按发布/修改日期排序?

提前谢谢你。

2 个答案:

答案 0 :(得分:1)

试试这段代码:

<div class="custom-category">
    <?php
      $post_tags_show_text = __('Tags', 'directory');

      $terms = wp_get_post_terms ( $cs_post_id, 'directory-tag', array('orderby' => 'date') );

      if ( isset($terms) ){ ?>
        <div class="cs-tags"> <!-- cs Tages Start -->
          <h5><?php echo esc_attr($post_tags_show_text);?></h5>
          <ul>
          <?php
          foreach($terms as $term) {
              echo "<li><a href='".get_term_link($term)."' title='".$term->name."'>".$term->name."</a></li>";
          }
          ?>
          </ul>
        </div>
    <?php
     } ?>
</div>

答案 1 :(得分:0)

https://wordpress.org/support/topic/query-sort-order-with-custom-post-types-and-based-on-custom-field

您需要在某处定义它。它看起来像这样

'orderby' => 'meta_value', 
'order' => 'ASC');

请参阅上面的链接