按POST和Desc查询POST订单不起作用

时间:2015-01-05 作者:Kadix

I have a query that displays post the order of the post 1 to 10and front-end added: <?php print intval( $post->menu_order );?>º there shows 1º, 2º, 3º ... 10º

must reverse the display but keep the number of order to stay well10º, 9º ... 1º

The post number 1, will remain the 1º but should appear at the end. I do not know how to do this work :(

and not work for me with \'orderby = > \'DESC\'

Any idea?

my code:

<?php query_posts(array(\'post_type\'=>\'ranking\')); ?>
            <?php $mypost = array( 
                \'post_type\' => \'ranking\',
                \'orderby\' => \'post\',                                     
                \'posts_per_page\' => 10,
                \'meta_key\'    => \'top10\',
                \'meta_value\'    => \'sim\'
                     );
            $loop = new WP_Query( $mypost ); ?>
            <!-- Cycle through all posts -->
            <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
             content format one...       

and it continues on the same page 11 to 50 whith:

 <?php query_posts(array(\'post_type\'=>\'ranking\')); ?>
            <?php $mypost = array( 
                \'post_type\' => \'ranking\', 
                \'orderby\' => \'post\',                  
                \'showposts\' => -1 ,
                \'meta_key\'    => \'top10\',
                \'meta_value\'    => \'nao\'               
                 );

            $loop = new WP_Query( $mypost ); ?>
            <!-- Cycle through all posts -->
            <?php while ( $loop->have_posts() ) : $loop->the_post(); ?> 
            content format two...
1 个回复
最合适的回答,由SO网友:cybmeta 整理而成

post 不是的有效值orderby 参数都不是DESC. 您可以选择any of these values. 此外,您应该停止使用query_post.

<?php
$args = array( 
            \'post_type\'      => \'ranking\',
            \'orderby\'        => \'menu_order\', 
            \'order\'          => \'DESC\',                                    
            \'posts_per_page\' => 10,
            \'meta_key\'       => \'top10\',
            \'meta_value\'     => \'sim\'
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) {
     $loop->the_post();
     //Do whatever you want with the posts
}
//After the loop reset post data
wp_reset_postdata();
?>

结束

相关推荐