【发布时间】:2016-11-11 05:48:25
【问题描述】:
我正在为我的 wordpress 网站上的自定义帖子类型创建搜索功能,我需要根据 ACF True/False 字段过滤掉搜索结果。我必须使用 WP_Query 来传递参数,因为通用 wordpress 循环不允许这样做,但是当我使用 WP_Query 时,查询会根据我传递的参数返回所有帖子,而忽略实际的搜索词。
<?php $args = array(
'post_type' => 'work',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'work_hidden',
'value' => '0',
'compare' => '=='
)
)
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) {
$the_query->the_post();
include "partials/work-card.php";
}
endif; ?>
如何使用 WP_Query 来包含搜索词和参数。
非常感谢!
【问题讨论】:
标签: php wordpress advanced-custom-fields