简体   繁体   English

根据自定义参数在Wordpress循环中找不到帖子

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

I've set one simply parameter in my args array but not getting any of the appropriate posts through. 我在我的args数组中设置了一个简单的参数,但没有得到任何适当的帖子。

With use of Advanced Custom Fields, I created a 'Select' option in the 'post' types, and the option being 'Featured: Yes'. 通过使用“高级自定义字段”,我在“发布”类型中创建了“选择”选项,并且该选项为“功能:是”。 About 4 are set as featured but still states no posts are found. 大约有4个被设置为特色,但仍未找到任何帖子。

** I've provided a screenshot of the page. **我提供了该页面的屏幕截图。 As you'll see, there are posts on the bottom half of the page which are coming through using the standard loop, but I've setup a new loop to display just Featured posts at the top. 如您所见,页面的下半部分使用标准循环来发布帖子,但是我设置了一个新的循环,仅在顶部显示精选帖子。 Maybe I am meant to end the global loop first? 也许我打算先结束全局循环?

Here is my current setup: 这是我当前的设置:

<?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(). ?>

Advanced Custom Fields 高级自定义字段

在此处输入图片说明

A post that has been set to Featured. 已设为“精选”的帖子。

在此处输入图片说明

Post Page: 帖子页:

在此处输入图片说明

I suspect it's because you can have several checkboxes in the one field, meaning ACF needs to store the value as an array, rather than a single string. 我怀疑这是因为您可以在一个字段中包含多个复选框,这意味着ACF需要将值存储为数组,而不是单个字符串。

I just did a test, and this is the meta_value I get based on your setup: 我刚刚进行了测试,这是根据您的设置获得的meta_value

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

which won't match the literal Yes you're using. 与您使用的字面值“ Yes不匹配。

In this particular case, I'd try using ACF's True / False field type. 在这种情况下,我会尝试使用ACF的True / False字段类型。 If true, it stores 1 in the meta_value field, which would work with the approach you're using. 如果为true,它将在meta_value字段中存储1 ,这将与您使用的方法一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM