Working within php, I am passed an array of objects ( $terms ):
array(15) {
[0]=>
object(WP_Term)#341 (10) {
["term_id"]=>
int(263)
["name"]=>
string(15) "Moo"
["slug"]=>
string(15) "moo"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(263)
["taxonomy"]=>
string(9) "my_topics"
["description"]=>
string(0) ""
["parent"]=>
int(0)
["count"]=>
int(29)
["filter"]=>
string(3) "raw"
}
[1]=>
object(WP_Term)#342 (10) {
["term_id"]=>
int(264)
["name"]=>
string(10) "Bark"
["slug"]=>
string(10) "bark"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(264)
["taxonomy"]=>
string(9) "my_topics"
["description"]=>
string(0) ""
["parent"]=>
int(0)
["count"]=>
int(17)
["filter"]=>
string(3) "raw"
}
[2]=>
object(WP_Term)#343 (10) {
["term_id"]=>
int(281)
["name"]=>
string(16) "Meow"
["slug"]=>
string(16) "meow"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(281)
["taxonomy"]=>
string(9) "my_topics"
["description"]=>
string(0) ""
["parent"]=>
int(266)
["count"]=>
int(2)
["filter"]=>
string(3) "raw"
}
[3]=>
object(WP_Term)#344 (10) {
["term_id"]=>
int(282)
["name"]=>
string(19) "Tweet"
["slug"]=>
string(19) "tweet"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(282)
["taxonomy"]=>
string(9) "my_topics"
["description"]=>
string(0) ""
["parent"]=>
int(266)
["count"]=>
int(4)
["filter"]=>
string(3) "raw"
}
[4]=>
object(WP_Term)#345 (10) {
["term_id"]=>
int(772)
["name"]=>
string(8) "Chirp"
["slug"]=>
string(8) "chirp"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(772)
["taxonomy"]=>
string(9) "my_topics"
["description"]=>
string(0) ""
["parent"]=>
int(0)
["count"]=>
int(3)
["filter"]=>
string(3) "raw"
}
}
In my real array, instead of [4], there are [14]...but that shouldn't matter because I can't rely on targeting by number.
If an object within the array contains "slug" value of "meow", I want to filter that object out and produce a new array with the rest of the objects in tact.
I need to exclude a specific object which has a specific value, in the array. My approach is to use 'array_filter' Here's where I am stuck (I feel like I'm so close but traversing arrays of objects can give me a hard time):
$refinedterms = array_filter($terms, function($obj){
echo objTEST;
var_dump($obj);
foreach($obj->WP_Term as $wpTermObj){
echo wpTermObjTEST;
var_dump($wpTermObj);
foreach ($wpTermObj->slug as $slug) {
echo slugTEST;
var_dump($slug);
if ($slug == 'meow') return false;
}
}
return true;
});
The echos and var_dumps are in place to help me debug. I feel like the fourth line is where something is a miss. Thank you in advance for any assistance, it is very much appreciated.