[ad_1]
I have the following query returning 24 rows on PHPMyAdmin
SELECT meta_value FROM wp_postmeta where meta_key like '%year%' and post_id IN (SELECT ID from wp_posts where post_status = 'publish' and post_type = 'inventory') GROUP BY meta_value order by meta_value
Then I added to this code:
$ar = new WP_Query("SELECT meta_value FROMwp_postmeta` where meta_key like ‘%year%’ and post_id IN (SELECT ID from wp_posts where post_status = ‘publish’ and post_type = ‘inventory’) GROUP BY meta_value order by meta_value “);
print_r($ar);
$choices = array();
while ($ar->have_posts()) : $ar->the_post();
echo “IDDDD”.$ar->ID.”<br>”;
$choices[] = array(‘text’ => $ar->meta_value, ‘value’ => $ar->meta_value);
endwhile;
$field->choices = $choices;`
But it doesn’t print anything… what am I doing wrong with this syntax?
