通过post_title订购关系ACF

时间:2019-04-09 20:29:56

标签: php wordpress advanced-custom-fields

我的meta_query仅按ID排序,但我需要按post_title排序

这里是我正在使用的查询

<?php
                                    $args = array(
                                        'orderby'        => 'meta_value',       // Or post by custom field
                                        'order'          => 'DESC',       // Or post by custom field
                                        'meta_key'       => 'case-solucao',
                                        'post_type'      => 'testemunho',          // Just the post type
                                        'posts_per_page' => -1,                 // Show all available post
                                    );
                                        query_posts($args);
                                        while(have_posts()){
                                            the_post();
                                            $solucoesCases = get_field('case-solucao');
                                            foreach ($solucoesCases as $solCase) {
                                                // echo count($solCase->ID);

                                            }
                                            echo $solCase->ID ." - ". $solCase->post_title."\n";
                                        }
                                    ?>

我有一个Custon字段,它将解决方案链接到post_type。但是它只能按ID排序,而我需要按Post_title排序。 我真的迷路了。希望有人能帮助我。

1 个答案:

答案 0 :(得分:0)

尝试一下。如果是的话,您需要在自定义字段中显示标题。

$args = array(
   'orderby'        => 'title',        // This will order the post by title
   'post_type'      => 'testemunho',   // Just the post type
   'posts_per_page' => -1,             // Show all available post
);
query_posts($args);
while(have_posts()){
    the_post();
    foreach ($solucoesCases as $solCase) {
        $solucoesCases = get_field('case-solucao', $solCase->ID ); // add the ID of the post_type
        echo $solCase->ID ." - ". $solCase->post_title."\n"; // will print all the title
        echo $solucoesCases;
    }
}