Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Get dropdown list of products WooCommerce
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => '12',
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
)
);
$products = new WP_Query($args);
print '<select>';
while ($products->have_posts()) : $products->the_post();
print '<option value="' . get_the_ID() . '">' . get_the_title() . '</option>';
endwhile;
print '</select>';
wp_reset_query();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment