2016-12-13 3 views
0

私はWordPress Postからのタグのリストを含む連想配列を持っています。これは、wp_get_post_tags連想配列に特定の値があるかどうかを確認するには

array(3) { [0]=> object(WP_Term)#300 (10) { ["term_id"]=> int(22) ["name"]=> string(10) "Case Study" ["slug"]=> string(10) "case-study" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(22) ["taxonomy"]=> string(8) "post_tag" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(6) ["filter"]=> string(3) "raw" } [1]=> object(WP_Term)#295 (10) { ["term_id"]=> int(9) ["name"]=> string(9) "Microsoft" ["slug"]=> string(9) "microsoft" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(9) ["taxonomy"]=> string(8) "post_tag" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(11) ["filter"]=> string(3) "raw" } [2]=> object(WP_Term)#367 (10) { ["term_id"]=> int(27) ["name"]=> string(10) "SharePoint" ["slug"]=> string(10) "sharepoint" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(27) ["taxonomy"]=> string(8) "post_tag" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(10) ["filter"]=> string(3) "raw" } } 

WordPressの関数の出力であり、私はそれは、タグ名「のSharePoint」を含んでいるかどうかを確認したいです。私は様々なリソースを使いましたが、それを行う方法を見つけることができません。これは私がこれをやってみましたが、それは

//$a is the Array 
foreach ($a as $key=>$value) { 
if ($value=='SharePoint'){ 
echo "True" 
} 

親切に助けを動作しませんでしたアレイ

Array 
(
    [0] => stdClass Object 
     (
      [term_id] => 4 
      [name] => tag2 
      [slug] => tag2 
      [term_group] => 0 
      [term_taxonomy_id] => 4 
      [taxonomy] => post_tag 
      [description] => 
      [parent] => 0 
      [count] => 7 
     ) 

    [1] => stdClass Object 
     (
      [term_id] => 7 
      [name] => tag5 
      [slug] => tag5 
      [term_group] => 0 
      [term_taxonomy_id] => 7 
      [taxonomy] => post_tag 
      [description] => 
      [parent] => 0 
      [count] => 6 
     ) 

    [2] => stdClass Object 
     (
      [term_id] => 16 
      [name] => tag6 
      [slug] => tag6 
      [term_group] => 0 
      [term_taxonomy_id] => 16 
      [taxonomy] => post_tag 
      [description] => 
      [parent] => 0 
      [count] => 2 
     ) 

) 

の構造です。

答えて

2

あなたは近くにあったが、$の値がオブジェクトであることを忘れていないので、あなたのコードはこの方法を調整する必要があります。

foreach ($a as $key=>$value) { 
if ($value->name=='SharePoint'){ 
echo "True"; 
} 
関連する問題