我如何才能以升序显示这些帖子?

时间:2013-01-01 作者:Tom Geoco

我试图按降序显示以下帖子,从第一篇创建的帖子开始,到最后一页以最近创建的帖子结束。非常感谢您的帮助。这是我的代码:

<?php
$numofmebers = \'-1\';
if ( empty($_GET[\'page_id_all\']) ) $_GET[\'page_id_all\'] = 1;
    $count_post = 0;
        query_posts( array( \'posts_per_page\' => \'-1\', \'post_type\' => \'coach-instructor\' ,\'post_status\' => \'publish\') );
        while ( have_posts()) : the_post();
            $count_post++;
        endwhile;
            if ( $node->instructor_pagination == "Single Page" ) {$node->instructor_page_num = -1;}
            query_posts( array(\'posts_per_page\' => "$node->instructor_page_num", \'paged\' => $_GET[\'page_id_all\'], \'post_type\' => \'coach-instructor\' ,\'post_status\' => \'publish\') ); 
        $counter_news = 0;
        while ( have_posts()) : the_post();
        $counter_news++;
        $image_id = get_post_thumbnail_id ( $post->ID );
        $coach_istructor_meta = get_post_meta($post->ID, "cs_coach_istructor_meta", true);
            if ( $coach_istructor_meta <> "" ) {
                $xmlObject_author = new SimpleXMLElement($coach_istructor_meta);
                    $about = $xmlObject_author->about;
                    $specialism = $xmlObject_author->specialism;
                    $qualifications = $xmlObject_author->qualifications;
                    $philosophy = $xmlObject_author->philosophy;
                    $contact = $xmlObject_author->contact;
            }
            else {
                $about = \'\';
                $specialism = \'\';
                $qualifications = \'\';
                $philosophy = \'\';
                $contact = \'\';
            }
?>

1 个回复
最合适的回答,由SO网友:Ed Burns 整理而成

请记住,最好避免使用query\\u posts,因为它会对主循环产生负面影响。更好的方法是创建WP\\u Query的新实例或更改主循环的查询参数。

要获取所需的订单,请尝试将以下内容添加到参数中:

array( \'posts_per_page\' => \'-1\', \'post_type\' => \'coach-instructor\' ,\'post_status\' => \'publish\', \'orderby\' => \'date\', \'order\' => \'ASC\')

结束

相关推荐

Order posts by price

我在一个页面上有一个产品列表,并试图通过一个名为“价格”的自定义字段进行订购。不幸的是,3950000美元比349000美元还要多。我使用了一些代码,但都不起作用。有人有什么建议吗?谢谢这是我尝试的第一个代码。$query = new WP_Query( array ( \'post_type\' => \'product\', \'orderby\' => \'meta_value\', \'meta_key\' => \'price\', \'order\' => \'ASC\