Download - File Dropper

Transcript
72
Creating Custom Post Types
global $post;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
Here, we are doing two things: grabbing the global $post array,
which we’re going to need to get our custom post values. Then
we’re doing something very important; we’re checking to see if
WordPress is currently autosaving. If it is, we’re going to want to
exit out of this function so we don’t accidently overwrite anything.
We’ll do the same thing later on.
$custom = get_post_custom($post->ID);
$address = $custom["address"][0];
$address_two = $custom["address_two"][0];
$city = $custom["city"][0];
$state = $custom["state"][0];
$zip = $custom["zip"][0];
$website = $custom["website"][0];
$phone = $custom["phone"][0];
$email = $custom["email"][0];
?>
Here is where we get any preexisting values so that the user
doesn’t have to enter them in every time they want to edit a given
post. The function get_post_custom() accepts a post ID as an
argument and will return a 2D associative array containing all of the
post’s custom data. We then assign each value its own variable,
which will make it easier to manage in the next set of code.
Note: since we can technically have multiple values for each
custom post type, that information is also returned as an array, so
we need to grab the first value of each array, which is at index 0.
Next up, we define and include a stylesheet that will be used specifically to style our meta box:
<style type="text/css">
<?php include('business-manager.css'); ?>
</style>