我这里有这段代码可以获取我的已发布和私人帖子:
$args = array(
'post_status' => array( 'publish', 'private'),
);
$query = new WP_Query( $args );
$posts = $query->posts;
现在,我尝试按post_status对其进行排序,以使私有密钥位于已发布的密钥之下,然后按日期排序。我的问题是我该怎么做?
我尝试过:
$args = array(
'post_status' => array( 'publish', 'private'),
'order_by' => array( 'post_status' => 'ASC')
);
$query = new WP_Query( $args );
$posts = $query->posts;
但是它并没有改变我的帖子顺序。
这是我显示帖子的方式
<?php if (have_posts()) : ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="title">
<h2><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
</div>
<div class="meta"><a href="<?php the_permalink() ?>"><?php the_time('d. F Y') ?></a> · <?php comments_popup_link(__('Write a comment', 'picolight'), __('1 comment', 'picolight'), __('% comments', 'picolight')); ?>
<?php
picolight_show_categories();
picolight_show_tags();
?>
<?php edit_post_link( __( '(Edit)', 'picolight' ), '<span class="edit-link">', '</span>' ); ?></div>
<div class="entry">
<?php if ( has_post_thumbnail() ) { ?>
<div class="thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail(); ?>
</a>
</div>
<div class="indexexzerpt">
<?php the_content(__('More »', 'picolight')); ?>
</div>
<?php }
else {
the_content(__('More »', 'picolight'));
} ?>
<?php if(wp_link_pages('echo=0') != "") {
echo '<div class="pagelinks">';
wp_link_pages();
echo '</div>';
} ?>
</div>
</div>
<?php endwhile; ?>
<?php
if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
else {
?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link(__('« Older articles', 'picolight')); ?></div>
<div class="alignright"><?php previous_posts_link(__('Newer articles »', 'picolight')); ?></div>
</div>
<?php } ?>
<?php else : ?>
答案 0 :(得分:1)
尝试一下(您的order by子句中的字段错误):
$args = array(
'post_status' => array( 'publish', 'private'),
'order_by' => array( 'post_date' => 'ASC')
);
$query = new WP_Query( $args );
$posts = $query->posts;