2017-09-14 12 views
0

Wordpress CMS上でPHPを使用してアルファベット順に配列をソートするにはどうすればよいですか?アルファベット順のソート配列PHP/wordpress

<?php if(count($terms_array) > 0) : foreach($terms_array as $term) : ?> 

<?php 
    $term = ''; 
    $args = array(
     'post_type' => 'book', 
     'posts_per_page' => -1, 
     'orderby' => 'menu_order', 
     'order' => 'ASC' 
    ); 

    $books_query = new WP_Query($args); 
?> 

<?php if ($books_query->have_posts()) : ?> 
+1

http://php.net/manual/en/function.sort.php – Calimero

+0

結果をアルファベット順に並べ替えるには、なぜ「menu_order」で検索するのですか? WP_Queryの関連フィールドにアルファベット順を指定しないのはなぜですか? – FluffyKitten

答えて

0

PHPのデフォルトの並べ替え機能を使用します。本当にあなたができる配列をソートするためにPHPの関数を使用し

<?php 
sort($terms_array); 

if(count($terms_array) > 0) : 

foreach($terms_array as $term) : 

     $term = ''; 
     $args = array(
      'post_type' => 'book', 
      'posts_per_page' => -1, 
      'orderby' => 'menu_order', 
      'order' => 'ASC' 
     ); 
     $books_query = new WP_Query($args) 

     if ($books_query->have_posts()) : 
?> 
関連する問題