我有一個WP_Query構建一個Bootstrap輪播。我添加了一個高級自定義字段單選按鈕,允許客戶在帖子上選擇「是/否」選項來「發送」此選項。我的WP_Query完美工作,沒有Meta Query,但是當我添加它時,它沒有任何結果。我不確定這是因爲這是否在archive.php上。我添加了一個動態類別,它只顯示當前類別的特色帖子(這也是完美的)。這只是ACF,似乎沒有工作。我已經驗證了這兩個鍵值&正在被存儲在數據庫中,就像在這裏被調用一樣。我甚至用get_field()語句成功地回顯了這個值,以確保它正常工作。我很難過。任何建議將不勝感激。WP_Query與高級自定義字段元查詢不起作用
這裏是我的代碼:
<?php
$qcatid = get_queried_object(); // So we can get the query category ID
$args2=array(
'post_type' => 'post',
'post_status' => 'publish',
'cat' => $qcatid->cat_ID, // Query the proper category
'orderby' => 'date',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'feature_in_slider_carousel',
'value' => 'Yes'
)
)
);
$mycat_query = null;
$mycat_query = new WP_Query($args2);
if($mycat_query->have_posts()) {
$slide_count = 0;
?>
<section id="featured-posts">
<div class="container">
<div class="row">
<div class="col-md-12">
<hr />
</div>
</div>
</div>
<div id="featured-carousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<?php
while ($mycat_query->have_posts()) : $mycat_query->the_post(); ?>
<div class="item <?php if ($slide_count == 1) { echo 'active';} ?>">
<div class="row">
<div class="col-sm-2 col-sm-offset-3">
<div class="whitepaper-img">
<a href="<?php the_permalink(); ?>">
<?php
include(TEMPLATEPATH . '/inc/icon-include.php');
if (has_post_thumbnail($post->ID)) {
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'whitepaper-carousel'); ?>
<img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" class="img-responsive" />
<?php }
else { ?>
<img src="<?php bloginfo('template_directory'); ?>/img/default-whitepaper.png" alt="<?php the_title(); ?>" class="img-responsive" />
<?php } ?>
</a>
</div>
</div>
<div class="col-sm-5">
<h3><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h3>
<?php the_excerpt();?>
<div class="post-tags">
<?php
$posttags = get_the_tags();
if ($posttags) {
echo '<ul class="list-inline">';
foreach($posttags as $tag) {
echo '<li><a href="'. get_bloginfo('url') .'/tag/' . $tag->slug . '/">' . $tag->name . '</a></li>';
}
echo '</ul>';
}
?>
</div>
</div>
</div>
</div>
<?php
$slide_count++;
endwhile; ?>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#featured-carousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#featured-carousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<hr />
</div>
</div>
</div>
</section>
<?php }
wp_reset_query();
?>
你在_Meta Query_中試過用'field_key'而不是'field_name'作爲_key_值嗎? –