0

I've searched and found many variations on adding custom meta to taxonomies - often its just for text fields and often to store a whole array of options.

One thing I haven't found is a way to register one checkbox on a custom taxonomy page. I've tried some more complex code that could save the checked box but wouldn't notice if it was unchecked - so I simplified the code to the basics and it still doesn't work.

Here is my code so far..

// A callback function to add a custom field to our "menu_page" taxonomy
function menupage_taxonomy_custom_fields() {

$altprice = get_option( 'mschema_altprice' );

?>

<tr class="form-field">
<th scope="row" valign="top">
    <label for="altprice_checkbox"><?php _e('Takeaway/Discount          Pricing?'); ?></label>
</th>
<td><input type="checkbox" id="altprice_checkbox" name="mschema_altprice"         value="1" <?php checked( 1, $altprice, false )?>/>

    <span class="description"><?php _e('Takeaway/Discount Pricing?');   ?></span>
</td>
</tr>

<?php
}

// A callback function to save our extra taxonomy field(s)
function save_taxonomy_custom_fields( ) {  


        $ap = ( isset( $_POST['mschema_altprice'] ) &&    $_POST['mschema_altprice'] ) ? 1 : 0 ;


    update_option( 'mschema_altprice', $ap );  

}  
// Add the fields to the "presenters" taxonomy, using our callback  function
add_action( 'menu_pages_edit_form_fields', 'menupage_taxonomy_custom_fields', 10, 2 );

// Save the changes made on the "presenters" taxonomy, using our callback  function
add_action( 'edited_menu_pages', 'save_taxonomy_custom_fields', 10, 2 );
0

Fortunately this guy has written a great taxonomy class to solve all of this :) https://en.bainternet.info/wordpress-taxonomies-extra-fields-the-easy-way/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.