Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- adicionando meta fields no cadastro de taxonomies / categories
- ATENÇÃO: LEMBRE-SE DE ALTERAR {taxonomy-slug} para o slug da sua taxonomia/ categoria. Por exemplo:
- Taxonomia = colecao
- {taxonomy-slug}_edit_form_fields = colecao_edit_form_fields ... e assim por diante!
- Para exibir o valor do campo no tema, faça o seguinte:
- <?php
- $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
- $tax_meta = get_option('term_'.$term->term_id);
- echo $tax_meta['{taxonomy-slug}_foto']; //não esqueça de alterar {taxonomy-slug} pelo slug da sua taxonomia/ categoria.
- ?>
- */
- add_action ('{taxonomy-slug}_edit_form_fields', '{taxonomy-slug}_tax_fields');
- add_action('{taxonomy-slug}_add_form_fields','{taxonomy-slug}_tax_fields');
- function {taxonomy-slug}_tax_fields( $tag ) { //check for existing featured ID
- $t_id = $tag->term_id;
- $Tax_meta = get_option( "term_$t_id");
- echo '<tr class="form-field">';
- echo ' <th scope="row" valign="top"><label for="{taxonomy-slug}_foto">Foto</label></th>';
- echo ' <td>';
- echo ' <input type="text" name="Tax_meta[{taxonomy-slug}_foto]" id="Tax_meta[{taxonomy-slug}_foto]" size="25" style="width:60%;" value="';
- echo ($Tax_meta['{taxonomy-slug}_foto']) ? $Tax_meta['{taxonomy-slug}_foto'] : '';
- echo '"><br />';
- echo ' <span class="description">URL da foto ou avatar. Utilize o menu Midia para fazer o upload do arquivo.</span>';
- echo ' </td>';
- echo ' </tr>';
- }
- // save extra taxonomy extra fields hook
- add_action ('edited_{taxonomy-slug}', 'save_extra_tax_fileds');
- add_action('created_{taxonomy-slug}','save_extra_tax_fileds');
- // save extra taxonomy extra fields callback function
- function save_extra_tax_fileds( $term_id ) {
- if ( isset( $_POST['Tax_meta'] ) ) {
- $t_id = $term_id;
- $Tax_meta = get_option( "term_$t_id" );
- $Tax_keys = array_keys($_POST['Tax_meta']);
- foreach ($Tax_keys as $key){
- if (isset($_POST['Tax_meta'][$key])){
- $Tax_meta[$key] = $_POST['Tax_meta'][$key];
- }
- }
- //save the option array
- update_option( "term_$t_id", $Tax_meta );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement