Created
October 26, 2015 12:08
-
-
Save palmiak/9f98bf4c565ce1bcbe62 to your computer and use it in GitHub Desktop.
Podpięcie pod [select] w contact form 7 taxonomii użytych przy wpisie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ses_add_select_to_contact_form ( $tag, $unused ) { | |
global $post; | |
//deklarujemy nazwę selecta dla którego mają być zaciągnięte dodatkowe wartości | |
if( $tag['name'] == 'wymiary'){ | |
//nazwa taxonomii | |
$taxonomy = 'wymiary'; | |
//nazwy dla pierwszego option w select - tego domyślnego | |
$tag['raw_values'][] = ''; | |
$tag['values'][] = ''; | |
$tag['labels'][] = 'Wymiary łóżeczka'; | |
} | |
//nazw może być kilka | |
if( $tag['name'] == 'kolor'){ | |
$taxonomy = 'kolor'; | |
$tag['raw_values'][] = ''; | |
$tag['values'][] = ''; | |
$tag['labels'][] = 'Kolor łóżeczka'; | |
} | |
//wyciągnięcie wszystkich wartości | |
$terms = get_the_terms($post->ID,$taxonomy); | |
if($terms){ | |
foreach($terms as $term){ | |
$tag['raw_values'][] = $term->name; | |
$tag['values'][] = $term->name; | |
$tag['labels'][] = $term->name; | |
} | |
} | |
return $tag; | |
} | |
add_filter( 'wpcf7_form_tag', 'ses_add_select_to_contact_form', 10, 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// używamy w formatce od formularza CF7 | |
//kolor i wymiary - tak jak $tag['name'] | |
[select* kolor] | |
[select wymiary] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment