查找具有特定值的数组多维数组wordpress in_array
|
我正在运行一个使用wpml的wordpress网站,这给了我很多尝试在威尔士语翻译后的帖子中的标签上运行查询的问题。
所以我想做的是一个小技巧,可以让我查询所有帖子,并使用wordpresses函数get_the_tags()找到具有特定标签的帖子。
我正在尝试使用in_array,它似乎不适用于wordpress输出的多维数组,这是来自print_r()的数组;
> Array (
> [629] => stdClass Object
> (
> [term_id] => 629
> [name] => bulletin
> [slug] => bulletin
> [term_group] => 0
> [term_taxonomy_id] => 630
> [taxonomy] => post_tag
> [description] =>
> [parent] => 0
> [count] => 2
> [object_id] => 19838
> )
>
> [631] => stdClass Object
> (
> [term_id] => 631
> [name] => english2
> [slug] => english2
> [term_group] => 0
> [term_taxonomy_id] => 632
> [taxonomy] => post_tag
> [description] =>
> [parent] => 0
> [count] => 1
> [object_id] => 19838
> )
>
> ) Array (
> [629] => stdClass Object
> (
> [term_id] => 629
> [name] => bulletin
> [slug] => bulletin
> [term_group] => 0
> [term_taxonomy_id] => 630
> [taxonomy] => post_tag
> [description] =>
> [parent] => 0
> [count] => 2
> [object_id] => 19842
> )
>
> [630] => stdClass Object
> (
> [term_id] => 630
> [name] => english1
> [slug] => english1
> [term_group] => 0
> [term_taxonomy_id] => 631
> [taxonomy] => post_tag
> [description] =>
> [parent] => 0
> [count] => 1
> [object_id] => 19842
> )
>
> ) Array (
> [0] => stdClass Object
> (
> [term_id] => 633
> [name] => welsh2
> [slug] => welsh2
> [term_group] => 0
> [term_taxonomy_id] => 634
> [taxonomy] => post_tag
> [description] =>
> [parent] => 0
> [count] => 1
> )
>
> ) Array (
> [0] => stdClass Object
> (
> [term_id] => 632
> [name] => welsh1
> [slug] => welsh1
> [term_group] => 0
> [term_taxonomy_id] => 633
> [taxonomy] => post_tag
> [description] =>
> [parent] => 0
> [count] => 1
> )
>
> )
这是我的代码,我只希望它定位名为welsh1的数组,这是数组中的最后一个。
// Global calls to the database
global $wpdb;
// Runs a query to get all results from the wp_posts table
$all = $wpdb->get_results( \"SELECT * FROM wp_posts\" );
// loops through each one
foreach($all as $v){
$tags = get_the_tags($v->ID);
if (in_array(\'welsh1\', $tags)) {
echo \"\'ph\' was found\\n\";
}
echo \"<pre>\";
print_r($tags);
echo \"</pre>\";
}
没有找到相关结果
已邀请:
1 个回复
扑北爱