我正在构建一个WordPress网站,该网站使用一个链接到我的自定义类别的自定义AJAX过滤器。
这是我的职责ajax-filter.php:
function filter() {
$uid = get_current_user_id();
$paged = ( get_query_var( \'page\' ) ) ? get_query_var( \'page\' ) : 1;
$customer_account = get_field(\'customer_account\', \'user_\'.$uid );
$args = array(
\'post_type\' => \'cpt\',
\'posts_per_page\' => -1,
\'orderby\' => \'date\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'customer\',
\'field\' => \'term_id\',
\'terms\' => $customer_account,
)
)
);
$the_query = new WP_Query($args);
$results = array();
if (!empty($the_query->posts))
{
foreach ($the_query->posts as $post)
{
$id = $post->ID;
array_push($results, array(
\'id\' => $id,
\'title\' => get_field(\'e_detail_title\', $id),
\'tax\' => get_the_terms( $post->ID, \'type\', $id ),
));
}
}
wp_reset_postdata();
$someJSON = json_encode($results);
// Convert JSON string to Object
$someObject = json_decode($someJSON);
foreach($someObject as $key => $value) {
echo $value->title;
}
die;
}
add_action( \'wp_ajax_filter\', \'filter\' );
add_action( \'wp_ajax_nopriv_filter\', \'filter\' );
我的问题是:
如何以我在ajax-filter.php? 使用我的数据($value->title)
Array
(
[0] => Array
[title] => title
[tax] => Array
(
[0] => WP_Term Object
(
[term_id] => 54
)
)
)