我用Wordpress制作了一个AJAX过滤器,但我的循环不起作用。谁能帮我做这个?
我试图取回与ACF一起使用的自定义字段。
function filter_reports() {
global $customer_account;
$args = array(
\'post_type\' => \'ebooks\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'customer\',
\'field\' => \'term_id\',
\'terms\' => $customer_account,
),
array(
\'taxonomy\' => \'disease\',
\'field\' => \'term_id\',
\'terms\' => $_POST[\'options\'],
)
),
);
$the_query = new WP_Query( $args );
$results = array();
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$id = get_the_ID();
array_push($results, array(
\'id\' => $id,
\'title\' => get_field(\'title\', $id),
\'chair\' => get_field(\'e-chair\', $id),
));
}
}
echo json_encode($results);
die;
}
add_action( \'wp_ajax_filter_reports\', \'filter_reports\' );