Skip to content

Instantly share code, notes, and snippets.

@mikeott
Last active October 11, 2023 07:20
Show Gist options
  • Save mikeott/b2aa1487c61322df816f4d0b5a9e92a4 to your computer and use it in GitHub Desktop.
Save mikeott/b2aa1487c61322df816f4d0b5a9e92a4 to your computer and use it in GitHub Desktop.
Gravity Forms Product names for use in field
<?php /* Product names for use in Gravity Forms field */
function ra_all_product_names() {
$args = array(
'post_type' => 'product',
'orderby' => 'title',
'order' => 'asc',
'posts_per_page' => -1
);
$gchoice_count = 1;
$input_count = 1;
$input_id = 1;
$for = 1;
$for_id = 1;
$query = new WP_Query($args);
while ($query->have_posts()) : $query->the_post(); ?><div class="gchoice gchoice_28_6_<?php echo $gchoice_count++; ?>"><input type="checkbox" class="gfield-choice-input" value="<?php echo the_title(); ?>" name="input_6.<?php echo $input_count++; ?>" id="choice_28_6_<?php echo $input_id++; ?>" /> <label for="choice_28_6_<?php echo $for++; ?>" id="choice_28_6_<?php echo $for_id++; ?>" class="gform-field-label gform-field-label--type-inline"><?php echo the_title(); ?></label></div><?php endwhile;
wp_reset_postdata();
} ?>
<script>
jQuery( document ).ready(function() {
jQuery('#input_28_7').html('<?php echo ra_all_product_names(); ?>');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment