如何使用选择器高级自定义字段指定自定义 post 类型的查询?
How to specify a query for a custom post type using the selector advanced custom field?
我正在尝试过滤我的 'Campaigns' 自定义 post 类型,只显示 post 的 select 高级自定义字段设置为 'Featured Campaign'. select acf 的值只能是 'Featured Campaign' 或 'Not a Featured Campaign'
到目前为止这是我的代码,但它显示的不是 'Campaign' 和 'Featured Campaign' select,而是最近上传的 'Campaign'
如有任何帮助,我们将不胜感激。提前致谢!
<?php
$args = array(
'posts_per_page' => 1,
'post_status' => 'publish',
'post_type' => 'campaigns',
'meta_query' => array (
'key' => 'featured',
'value' => 'Featured Campaign'
)
);
query_posts( $args );
if (have_posts()) :
while (have_posts()) : the_post();
?>
<div class="post">
<?php the_post_thumbnail(); ?>
<h3 class="post__title heading--primary u-uppercase"><?php the_title(); ?></h3>
<p class="text-color--primary"><?php the_field(campaign_category); ?></p>
</div>
<?php
endwhile;
wp_reset_query();
endif;
?>
感谢评论区CBroe回复如下:
meta_query
期望嵌套数组,即使在一个查询的情况下也是如此。 $args 数组已更改为并且现在按预期工作:
$args = array(
'posts_per_page' => 1,
'post_status' => 'publish',
'post_type' => 'campaigns',
'meta_query' => array (
array (
'key' => 'featured',
'value => 'Featured Campaign'
)
)
);
我正在尝试过滤我的 'Campaigns' 自定义 post 类型,只显示 post 的 select 高级自定义字段设置为 'Featured Campaign'. select acf 的值只能是 'Featured Campaign' 或 'Not a Featured Campaign'
到目前为止这是我的代码,但它显示的不是 'Campaign' 和 'Featured Campaign' select,而是最近上传的 'Campaign'
如有任何帮助,我们将不胜感激。提前致谢!
<?php
$args = array(
'posts_per_page' => 1,
'post_status' => 'publish',
'post_type' => 'campaigns',
'meta_query' => array (
'key' => 'featured',
'value' => 'Featured Campaign'
)
);
query_posts( $args );
if (have_posts()) :
while (have_posts()) : the_post();
?>
<div class="post">
<?php the_post_thumbnail(); ?>
<h3 class="post__title heading--primary u-uppercase"><?php the_title(); ?></h3>
<p class="text-color--primary"><?php the_field(campaign_category); ?></p>
</div>
<?php
endwhile;
wp_reset_query();
endif;
?>
感谢评论区CBroe回复如下:
meta_query
期望嵌套数组,即使在一个查询的情况下也是如此。 $args 数组已更改为并且现在按预期工作:
$args = array(
'posts_per_page' => 1,
'post_status' => 'publish',
'post_type' => 'campaigns',
'meta_query' => array (
array (
'key' => 'featured',
'value => 'Featured Campaign'
)
)
);