Hi Laura,
The company select field works properly when the form is added into a page directly.
( e.g. hidden link )
This suggests that there is something wrong with the way the form is being included on the archive page, multiple times.
( hidden link )
One thing I noticed is that the IDs "formButton" & "form1" are repeating on the page, which makes their usage invalid.
A single page can only contain one unique instance of an ID.
( ref: hidden link )
You can convert the "formButton" & "form1" into classes in HTML and update your script accordingly.
If your goal is only to show an alphabetically ordered list of companies, as a drop-down field in a form, you can also follow a different approach:
1. For your "Contact Forms" post type, you can add a new custom field named "Company Name" and set it to be of type "select".
Note: you don't have to include all the options manually, as we'll generate them dynamically.
2. To generate the options, from the published posts in "Enhanced Listings" post type, you can add the following code, in your active theme's "functions.php" file:
add_filter( 'wpt_field_options', 'populate_select_for_companies', 10, 3);
function populate_select_for_companies( $options, $title, $type ){
switch( $title ){
case 'Company Name':
$options = array();
$args = array(
'post_type' => 'enhanced-listing',
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC'
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$options[] = array(
'#value' => $post->post_title,
'#title' => $post->post_title,
);
}
break;
}
return $options;
}
Note: Please make sure the title "Company Name" matches the title of the new custom field that was created.
I hope this helps and please let me know how it goes.
regards,
Waqar