[英]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.