Skip to content

Instantly share code, notes, and snippets.

@palmiak
Created October 26, 2015 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palmiak/9f98bf4c565ce1bcbe62 to your computer and use it in GitHub Desktop.
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
<?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);
<?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