Skip to content

Instantly share code, notes, and snippets.

@sunilw
Created June 28, 2014 05:16
Show Gist options
  • Save sunilw/90192f0d233ef5b0dd0e to your computer and use it in GitHub Desktop.
Save sunilw/90192f0d233ef5b0dd0e to your computer and use it in GitHub Desktop.
/**
* 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