[英]Get wordpress authors in order by the number of custom posts published
[英]Wordpress get published and private posts, then order them
我在這里有這個代碼,可以獲取我發布的和私人的帖子:
$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 : ?>
試試這個(你的 order by 子句中有一個錯誤的字段):
$args = array(
'post_status' => array( 'publish', 'private'),
'order_by' => array( 'post_date' => 'ASC')
);
$query = new WP_Query( $args );
$posts = $query->posts;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.