Hi, thank you for replying. You can see the site here
Here are my two functions:
// Contact Form 7 custom tag //
function custom_form_tag_angebote() {
wpcf7_add_form_tag( 'angebote*', 'custom_select_handler', array( 'name-attr' => true ) );
}
add_action( 'wpcf7_init', 'custom_form_tag_angebote' );
function custom_select_handler( $tag ) {
global $post;
$page_slug = $post->post_name;
if ( is_archive() ) {
$terms = get_the_terms( get_the_ID(), 'stellen' );
foreach ( $terms as $term ) {
$page_slug = $term->slug;
}
}
$args = array(
'post_type' => 'stellenangebote',
'stellen' => $page_slug,
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
$custom_select = '';
if ( $query->have_posts() ) {
$custom_select .= sprintf( '<span class="wpcf7-form-control-wrap %s-wrap">', $tag->name );
$custom_select .= sprintf( '<select id="%1$s" class="%1$s" name="%1$s" class="wpcf7-form-control wpcf7-select wpcf7-validates-as-required" id="%1$s" aria-required="true" aria-invalid="false">', $tag->name );
$custom_select .= sprintf( '<option value="" class="%1$s">Bitte Job w?hlen</option>', $tag->name );
while ( $query->have_posts() ) {
$query->the_post();
$the_title = the_title( '', '', false );
$custom_select .= sprintf( '<option value="%1$s" class="%2$s--selected" >%1$s</option>', $the_title, $tag->name);
}
$custom_select .= '</select>';
$custom_select .= '</span>';
}
// restore orginal query
wp_reset_postdata();
return $custom_select;
}
function custom_radio_confirmation_validation_filter( $result, $tag ) {
if ( 'bewerber-angebote' == $tag->name ) {
$test_custom_select = $_POST['bewerber-angebote'];
if ( empty( $test_custom_select ) ) {
$result->invalidate( $tag, 'Das Feld ist erforderlich.' );
}
}
return $result;
}
add_filter( 'wpcf7_validate_angebote*', 'custom_radio_confirmation_validation_filter', 20, 2 );