Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladimirlukyanov/2d39d4bd42cf6343ef38 to your computer and use it in GitHub Desktop.
Save vladimirlukyanov/2d39d4bd42cf6343ef38 to your computer and use it in GitHub Desktop.
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