Created
February 3, 2012 15:12
-
-
Save derpixler/1730623 to your computer and use it in GitHub Desktop.
add form fields to custom taxonomy
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 edit_category_form($tag){ | |
$taxonomy = $tag->taxonomy ; | |
if( $taxonomy != 'category' ){ | |
$taxonomy = 'custom_taxonomy'; | |
} | |
$args = array( 'custom_taxonomy' => array( | |
array( 'slug' => 'produkt', | |
'title' => 'Beschreibungstext <br />innerhalb eines Tabs', | |
'desc_nopost' => 'Es wurden noch keine Beschreibungen verfasst!</b><br /> <a href="' . get_bloginfo( 'Home' ) . '/wp-admin/post-new.php?post_type=descriptions" target="_blank">Hier kannst du eine neue Beschreibung verfassen.</a>', | |
'desc' => 'Mit diesem Dropdown kann ein Beschreibungstext für diese Kategorie, festgelegt werden, der innerhalb eines <b>Tabs</b> angezeigt wird.</span>', | |
'post_type' => 'tag' | |
) | |
) | |
); | |
foreach($args[$taxonomy] as $arg_key => $arg){ | |
$output .= '<table class="form-table">'; | |
$output .= '<tbody><tr class="form-field form-required">'; | |
$output .= '<tr valign="top"><th scope="row">' . $arg['title'] . '</th>'; | |
$output .= '<td id="front-static-pages"> | |
<fieldset> | |
<legend class="screen-reader-text"><span>Danke Text (bei Buchung):</span></legend> | |
<p> | |
<label>'; | |
$the_query = new WP_Query('post_type=' . $arg['post_type'] . '&posts_per_page=200'); | |
if( $the_query->found_posts == 0){ | |
$output .= '<b>' . $arg['desc_nopost']; | |
}else{ | |
$PostParm = 'category_' . $arg['post_type'] . '_' . $_GET['tag_ID'] . '_' . $arg['slug']; | |
$output .= '<input type="hidden" name="post_type" value="' . $arg['post_type'] . '">'; | |
$output .= '<select name="' . $PostParm . '" style="width:45%">'; | |
$output .= '<option value="0"> -- Wähle eine Beschreibung -- </option>'; | |
while ( $the_query->have_posts() ) : $the_query->the_post(); | |
if( get_the_ID() == get_option( $PostParm ) ){ | |
$selected = ' selected="selected" '; | |
}else{ | |
$selected = FALSE; | |
} | |
$output .= '<option value="' . get_the_ID() . '"' . $selected . '>' . get_the_title() . '</option>'; | |
endwhile; | |
$output .= '</select>'; | |
$output .= "<input type='hidden' name='args_as_json[]' value='" . $arg['slug'] . "' />"; | |
} | |
$output .= '</label></p><span class="description">' . $arg['desc'] . '</td>'; | |
$output .= '</tr></tbody></table>'; | |
} | |
echo $output; | |
} | |
function edit_category(){ | |
$trem_calc = $_POST['fieldname'] . '_identifyer'; | |
$oldEntries = get_option( $trem_calc ); | |
if( isset( $_POST['fieldname'] ) && $_POST['fieldname'] != $oldEntries ) { | |
if( !$oldEntries ){ | |
add_option( $_POST['id'], $_POST['fieldname'] ); | |
}else{ | |
update_option( $_POST['id'], $_POST['fieldname'] ); | |
} | |
} | |
} | |
add_action( 'edit_term_taxonomy', 'edit_category', 1 ,2 ); | |
add_action( 'edit_tag_form_fields', 'edit_category_form', 1 ,2 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment