// Form to add a record to display products dropdown v1.2 starts echo '<form id="add-record-form" style="display: flex; flex-direction: row;"> <div class="main_container" style="margin-right: 20px;"> <label for="product_name">Product Name:</label> <select id="product_name" name="product_name">'; // Retrieve product names from the database $query = new WP_Query(array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => '-1' )); if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); echo '<option value="' . get_the_title() . '">' . get_the_title() . '</option>'; endwhile; wp_reset_postdata(); else: echo '<option value="">No products found</option>'; endif; echo '</select> </div>'; // v1.2 stops
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter