簡體   English   中英

WordPress自定義帖子不顯示特色

[英]Wordpress custom post not showing featured

創建新的wordpress主題時,我遇到了一個奇怪的問題。 所以也許是因為我整天都在這里,但是需要查看是否有人可以發現我的錯誤或查看問題所在。

我正在嘗試按照類別名稱顯示“精選”帖子,如果在wp-admin部分中選中了該帖子,則僅顯示該帖子。 但是,我在代碼中定義了此代碼,但無論顯示與否,它都會顯示最新的帖子。

<?php

            $args = array(
                'post_type' => 'post',
                'category_mame' => 'featured',
                'posts_per_page' => 1
            );

            $the_query = new WP_Query( $args );

            ?>

            <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

            <div class="push_2 grid_10 omega clearfix">
                <article>

                    <?php get_template_part( 'content', 'post' ); ?>

                </article>
            </div>

        <?php endwhile; endif; ?>

    </div>

請先改變這個

'category_mame' => 'featured', 

'category_name' => 'featured', // name not mame 

是Wordpress的內置狀態參數。

我不知道這是否正是您要搜索的內容,但是如果將post_status添加到$args -array,則可以在狀態后查詢帖子:

 $args = array(
            'post_type' => 'post',
            'category_mame' => 'featured',
            'posts_per_page' => 1,
            'post_status' => 'publish',   //or 'draft', 'trash', 'pending', ... (see the link above)

        );


希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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