php WP_Query('orderby=post_date') 不适用于 wordpress
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4530121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WP_Query('orderby=post_date') not working with wordpress
提问by Poelinca Dorin
WP_Query('orderby=post_date')
is not working with wordpress.
WP_Query('orderby=post_date')
不适用于 wordpress。
how do I sort my posts in descending order?
如何按降序对我的帖子进行排序?
回答by Poelinca Dorin
WP_Query('orderby=date&order=DESC')
回答by Sudharshan
The following 3 parameters will give you the posts in Ascending order from the date it was published (i.e The older posts will be shown first)
以下 3 个参数将为您提供自发布之日起按升序排列的帖子(即较旧的帖子将首先显示)
'post_status' => 'publish', 'orderby' => 'publish_date', 'order' => 'ASC'
'post_status' => 'publish', 'orderby' => 'publish_date', 'order' => 'ASC'
When you change the orderto DESCyou will get the posts in Descending order from the date it was published (i.e The latest posts will be shown first)
当您将顺序更改为DESC 时,您将获得从发布之日起按降序排列的帖子(即最新的帖子将首先显示)
'post_status' => 'publish', 'orderby' => 'publish_date', 'order' => 'DESC'
'post_status' => 'publish', 'orderby' => 'publish_date', 'order' => 'DESC'
<?php
$postsPerPage = 10;
$page = 1;
?>
<?php
$query = new WP_Query(array(
'cat' => 4,
'post_status' => 'publish',
'orderby' => 'publish_date',
'order' => 'ASC',
'paged' => $page,
'posts_per_page' => $postsPerPage));
?>
回答by Gerald Schneider
To order by the modification date you have use orderby=modified
.
要按修改日期订购,请使用orderby=modified
.
WP_Query( 'orderby=modified&order=DESC' )
See the documentationfor more possible values.
有关更多可能的值,请参阅文档。
回答by Harsh Kashyap
Try this
尝试这个
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
"post_type" => "post",
"post_status" => "publish",
"paged" => $paged,
"orderby" => "date",
"order" => 'ASC'
);
WP_Query($args);
回答by Theva
If you are using PostTypesOrder plugin
it might globally modify your query, in order to avoid this behaviour to particular post type
如果您正在使用PostTypesOrder plugin
它可能会全局修改您的查询,以避免这种行为到特定的帖子类型
add_filter('pto/posts_orderby/ignore', 'theme_pto_posts_orderby', 10, 3);
function theme_pto_posts_orderby($ignore, $orderBy, $query)
{
if( (! is_array($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'post') ||
(is_array($query->query_vars) && in_array('post', $query->query_vars)))
$ignore = TRUE;
return $ignore;
}