Created
June 28, 2014 05:16
-
-
Save sunilw/90192f0d233ef5b0dd0e to your computer and use it in GitHub Desktop.
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
/** | |
* There's no getting around it: | |
* post meta in wordpress is insanely difficult | |
* even with a plugin or a library, wordpress post meta simply sucks to work with | |
* | |
*/ | |
add_action( 'add_meta_boxes', 'truckpost_meta' ); | |
function truckpost_meta() { | |
add_meta_box('trucks-meta', 'Feature', 'featured_truck_cb', 'larkin_truck', 'side' ) ; | |
} | |
function featured_truck_cb($post) { | |
$truck_is_featured = get_post_meta( $post->ID, 'truck_is_featured', true ); | |
?> | |
<select name="featured"> | |
<option value="No">No</option> | |
<option value="Yes">Yes</option> | |
</select> | |
<?php } | |
add_action( 'save_post', 'save_truck_meta' ); | |
function save_truck_meta( $post_ID ) { | |
global $post; | |
if( $post->post_type == "larkin_truck" ) { | |
if ( isset( $_POST ) ) { | |
update_post_meta( $post_ID, 'truck_is_featured', strip_tags( $_POST['truck_is_featured'] ) ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment