【发布时间】:2017-06-12 22:50:06
【问题描述】:
我正在尝试使用 pre_get_posts 修改查询,以便仅在存档页面上显示提供学生折扣的学校。有问题的字段称为“student_discount”,是一个复选框,如果为真则返回 1。
当我使用 get_post_custom 来回显值时,它是“_student_discount: Array”。
这是我目前拥有的:
function show_discounts( $query ) {
if( !is_admin() && $query->is_main_query() && is_post_type_archive( 'job_listing' ) ) {
$query->set( 'meta_query', array(
array(
'key' => 'student_discount',
'value' => 1,
'compare' => '='
),
));
}
add_action( 'pre_get_posts', 'show_discounts' );
【问题讨论】: