簡體   English   中英

Wordpress 獲得已發布和私人帖子,然后訂購它們

[英]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> &middot; <?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 &raquo;', 'picolight')); ?>
                    </div>
                    <?php }
                    else {
                        the_content(__('More &raquo;', '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(__('&laquo;  Older articles', 'picolight')); ?></div>
            <div class="alignright"><?php previous_posts_link(__('Newer articles &raquo;', '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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM