WP_Query issue | WordPress.org

[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?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer