Wordpress PHP MySQL query with a multidimensional array -
when run below php
in wordpress without foreach
printed multidimensional array. when use foreach
returns error 500
trying loop through results able select each name
, push array.
if assist me looping through array, great!
array ( [0] => stdclass object ( [term_taxonomy_id] => 26 [taxonomy] => product_brand [name] => authentic cheese [slug] => authentic-cheese ) [1] => stdclass object ( [term_taxonomy_id] => 27 [taxonomy] => product_brand [name] => robot [slug] => robot ) )
php
$q2 = "select t.term_taxonomy_id, t.taxonomy, e.name, e.slug wp_term_taxonomy t inner join wp_terms e on t.term_taxonomy_id = e.term_id taxonomy = 'product_brand'"; $r2 = $wpdb->get_results($q2); print_r($r2); foreach ($r2 $row) { echo $row['name']; }
you have array of objects in result. use:
foreach ($r2 $row) { echo $row->name; }
Comments
Post a Comment