Hallo nomainstream,
jetzt bin ich leider doch etwas aufgeschmissen, weil ich mich mit php nicht so wirklich auskenne. Bin da blutiger Anfänger.
Wenn ich die Anleitung http://thechoppr.com/blog/2013/10/ad...lect-dropdown/ richtig verstanden habe brauche ich das plugin advanced-custom-fields nicht, sondern gebe die benutzerdefinierten Felder in einem Beitrag an. Ich habe einen Beitrag Termine erstellt in dem ich 5 Felder mit 5 unterschiedlichen Terminen zum Testen eingerichtet habe.
Jetzt habe ich den Code der auf der Seite beschrieben ist wie folgt abgeändert:
<?php
[FONT=Verdana]//Benutzerdefiniertes Feld im Kontaktformular[/FONT]
[FONT=Verdana]function add_Terminanfrage_to_cf7() {[/FONT]
[FONT=Verdana] $html = '<p><label>Terminbuchung</label><select name="Terminbuchung" class="fs2">';[/FONT]
[FONT=Verdana] $the_query = new WP_Query();[/FONT]
[FONT=Verdana] $the_query->query('showposts=9999&category_name=Terminbuchung&orderby=date&order=DESC');[/FONT]
[FONT=Verdana] if ($the_query->have_posts()) {[/FONT]
[FONT=Verdana] while ($the_query->have_posts() ) {[/FONT]
[FONT=Verdana] $the_query->the_post();[/FONT]
[FONT=Verdana] $custom_fields = get_post_custom(get_the_ID());[/FONT]
[FONT=Verdana] if (!empty($custom_fields['Terminbuchung'][0])) {[/FONT]
[FONT=Verdana] $html .= '<option>' . $custom_fields['Terminbuchung'][0] . '</option>';[/FONT]
[FONT=Verdana] }[/FONT]
[FONT=Verdana] if (!empty($custom_fields['Terminbuchung'][1])) {[/FONT]
[FONT=Verdana] $html .= '<option>' . $custom_fields['Terminbuchung'][1] . '</option>';[/FONT]
[FONT=Verdana] }[/FONT]
[FONT=Verdana] if (!empty($custom_fields['Terminbuchung'][2])) {[/FONT]
[FONT=Verdana] $html .= '<option>' . $custom_fields['Terminbuchung'][2] . '</option>';[/FONT]
[FONT=Verdana] }[/FONT]
[FONT=Verdana] if (!empty($custom_fields['Terminbuchung'][3])) {[/FONT]
[FONT=Verdana] $html .= '<option>' . $custom_fields['Terminbuchung'][3] . '</option>';[/FONT]
[FONT=Verdana] }[/FONT]
[FONT=Verdana] if (!empty($custom_fields['Terminbuchung'][4])) {[/FONT]
[FONT=Verdana] $html .= '<option>' . $custom_fields['Terminbuchung'][4] . '</option>';[/FONT]
[FONT=Verdana] }[/FONT]
[FONT=Verdana] }[/FONT]
[FONT=Verdana] }[/FONT]
[FONT=Verdana] $html .='</select></p>';[/FONT]
[FONT=Verdana] return $html;[/FONT]
[FONT=Verdana]}
?>
[/FONT]Diesen Code habe ich in meine function.php meines Child Theme eingefügt.
Jetzt soll der zweite Code-Schnipsel, den ich wie folgt geändert habe in die "Template Page" - welche ist das? Doch nicht die Function.php?:
<?php
wpcf7_add_shortcode('wpcf7_add_wd', 'add_Terminbuchung_to_cf7', true);
print do_shortcode('[contact-form-7 404 "Not Found"]');
?>Jetzt hat der User TaeWoo unter den Comments geschrieben, das man für WP4 folgende Änderungen vornehmen soll:
[COLOR=#3F4549][FONT=Helvetica Neue]FREAKIN' AWESOME. Been looking for this solution EVERYWHERE. Thanks[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]if you're using Wordpress 4... here's what works:[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]function add_Terminbuchung_to_cf7() {[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]$html = '<select name="Terminbuchung" class="fs2">';[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]$custom_fields = get_post_custom(get_the_ID());[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]//die(print_r($custom_fields, true));
foreach(@$custom_fields['Terminbuchung'] as $date)
{
$html .= '<option>' . $date . '</option>';
}[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]$html .='</select>';[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]return $html;
}[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]wpcf7_add_shortcode('wpcf7_add_wd', 'add_Terminbuchung_to_cf7', true);
Ich weiß nicht wohin damit und wo ich das austauschen muss. Weißt du Rat? Bin völlig aufgeschmissen.
Vielen Dank im Voraus
LG Ulrich
[/FONT][/COLOR]