I have troubles with a website filter, where I would like to echo information of an array, but doing this the the ajax response will just stop.
我在网站过滤器上遇到了麻烦,我想要回显数组的信息,但是这样做ajax响应就会停止。
This is the array, that is printed with print_r
这是用print_r打印的数组
Array (
[0] => WP_Term Object (
[term_id] => 181
[name] => Football
[slug] => football
[term_group] => 0
[term_taxonomy_id] => 181
[taxonomy] => activities
[description] =>
[parent] => 0
[count] => 3
[filter] => raw )
Here is the code to print it this way:
下面是这样打印的代码:
$activities = get_the_terms($lesson_id,'activities',true);
print_r ($activities);
Now, I only want to print the name and I tried to use implode:
现在,我只想打印这个名字,我试着用内爆:
echo implode(', ',$activities) ;
But, with this line the Ajax response is empty. Same thing happens, when I simply echo one value from Array 0 or when I loop with foreach:
但是,使用这一行,Ajax响应是空的。同样的事情也会发生,当我简单地从数组0中返回一个值,或者当我用foreach循环时:
echo $activities[0]['name'];
The intention is to just print out the string "Football".
目的是仅仅打印出字符串“Football”。
1 个解决方案
#1
2
Your print_r tell that the array contain a collection of WP_Term objects so you should use
print_r告诉数组包含一个WP_Term对象集合,因此应该使用它
echo $activities[0]->name;
#1
2
Your print_r tell that the array contain a collection of WP_Term objects so you should use
print_r告诉数组包含一个WP_Term对象集合,因此应该使用它
echo $activities[0]->name;