簡體   English   中英

根據自定義參數在Wordpress循環中找不到帖子

[英]No posts found within the Wordpress loop based on custom arguments

我在我的args數組中設置了一個簡單的參數,但沒有得到任何適當的帖子。

通過使用“高級自定義字段”,我在“發布”類型中創建了“選擇”選項,並且該選項為“功能:是”。 大約有4個被設置為特色,但仍未找到任何帖子。

**我提供了該頁面的屏幕截圖。 如您所見,頁面的下半部分使用標准循環來發布帖子,但是我設置了一個新的循環,僅在頂部顯示精選帖子。 也許我打算先結束全局循環?

這是我當前的設置:

<?php 

// args
$args = array(
    'numberposts' => -1,
    'meta_key' => 'feature_post',
    'meta_value' => 'Yes'
);

// get results
$the_query = new WP_Query( $args );

// The Loop
?>
<?php if( $the_query->have_posts() ): ?>

<ul class="bxslider">

    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <li>
        <div class="featured-article">
            <div class="category-label">Health</div>
            <i class="category-label-end"></i>
            <?php echo the_post_thumbnail(); ?>
            <div class="featured-article-title">
                <h2><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h2>
            </div>
        </div>
    </li>

    <?php endwhile; ?>
</ul>

<?php else : echo '<p style="color:#fff;">no posts</p>'; ?>

<?php endif; ?>
<?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>

高級自定義字段

在此處輸入圖片說明

已設為“精選”的帖子。

在此處輸入圖片說明

帖子頁:

在此處輸入圖片說明

我懷疑這是因為您可以在一個字段中包含多個復選框,這意味着ACF需要將值存儲為數組,而不是單個字符串。

我剛剛進行了測試,這是根據您的設置獲得的meta_value

a:1:{i:0;s:3:"Yes";}

與您使用的字面值“ Yes不匹配。

在這種情況下,我會嘗試使用ACF的True / False字段類型。 如果為true,它將在meta_value字段中存儲1 ,這將與您使用的方法一起使用。

暫無
暫無

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

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