Last active
November 6, 2019 23:13
-
-
Save BretCameron/3d7487207d8eae1a2c7fc32d75ece448 to your computer and use it in GitHub Desktop.
Add a custom field type called "genre" to WordPress.
This file contains hidden or 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 // Add Custom Field Type: Genre | |
| function genre_meta_box() { | |
| add_meta_box( | |
| 'global-notice', | |
| __( 'Genre', 'sitepoint' ), | |
| 'genre_meta_box_callback', | |
| 'movies', | |
| 'side', | |
| 'low' | |
| ); | |
| } | |
| function genre_meta_box_callback() { | |
| global $post; | |
| $custom = get_post_custom($post->ID); | |
| $genre = $custom["genre"][0]; | |
| ?> | |
| <input style="width:100%" name="genre" value="<?php | |
| echo $genre; ?>" /> | |
| <?php | |
| } | |
| function save_genre(){ | |
| global $post; | |
| update_post_meta($post->ID, "genre", | |
| $_POST["genre"]); | |
| } | |
| add_action( 'add_meta_boxes', 'genre_meta_box' ); | |
| add_action( 'save_post', 'save_genre' ); |
Author
Why does this have printer_category? Was this a copy and paste from somewhere else?
@phoydar I adapted this gist from one of my real-world projects, so left "printer_category" in there by accident!
I've replaced it with "genre"!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why does this have printer_category? Was this a copy and paste from somewhere else?