VISUALLY SPACED

Icon

design / photography in the GSO

How to Enable WordPress to Define the Parent of a Custom Post Type

a blog I wrote for Beacon Technologies

Here is a script that will enable you to define a parent for a custom post type. You just need to include this in your functions.php file. In this code sample, “Product” is my custom post type but you will need to replace this with whatever you are wanting to define a parent for.

//Add the meta box callback function
function admin_init(){
add_meta_box("Product_parent_id", "Product Parent ID", "set_Product_parent_id", "Product", "normal", "low");
}
add_action("admin_init", "admin_init");

//Meta box for setting the parent ID
function set_Product_parent_id() {
 global $post;
 $custom = get_post_custom($post->ID);
 $parent_id = $custom['parent_id'][0];
 ?>
 <p>Please specify the ID of the page or post to be a parent to this Product.</p>
 <p>Leave blank for no heirarchy.&nbsp; Products will appear from the server root with no assocaited parent page or post.</p>
 <input type="text" id="parent_id" name="parent_id" value="<?php echo $post->post_parent; ?>" />
 <?php
 // create a custom nonce for submit verification later
 echo '<input type="hidden" name="parent_id_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
}

// Save the meta data
function save_Product_parent_id($post_id) {
 global $post;

// make sure data came from our meta box
 if (!wp_verify_nonce($_POST['parent_id_noncename'],__FILE__)) return $post_id;
 if(isset($_POST['parent_id']) && ($_POST['post_type'] == "Product")) {
 $data = $_POST['parent_id'];
 update_post_meta($post_id, 'parent_id', $data);
 }
}
add_action("save_post", "save_Product_parent_id");

The 3 functions in this script are:
function admin_init() Which calls the meta box.
function set_case_study_parent_id() Which creates the metabox.
function save_case_study_parent_id() Which saves the meta data in the database.

Once this script is in place, when you got to one of your custom posts there will be a box at the very bottom that says “Parent Product ID”. You must define the parent in this box by it’s page ID and not the permalink name.

Also if you want the parent to show up in the URL, you must make sure that you include this line in the $args array when you register your custom post type in the functions.php file

'rewrite' => array('slug' => 'product', 'with_front' => true)

You may have to go into your Permalinks settings and just click Save Changes to update the new URL structure.

Latest Work

Once again I am short on time but heavy on work. Here are my latest two sites:

New Work

I don’t have much time to update this but here is the lowdown:

Douglas Construction

Douglas Construction:

http://www.douglascr.com/

I redesigned their logo (not in the original scope of work, but I felt like it *had* to be done so I just did it for them). Then built out their custom design and their site. This site has a lot of mini galleries throughout which I felt was a nice touch. This is probably my favorite design lately.

 

Worldwide Auto Body

World Wide Auto Body:

http://www.worldwideautobodync.com/

Another similar build. Used their old logo – but their branding was more firmly established so I wasn’t going to mess with it. I am so fortunate to have a wonderful writer to help generate content. She is a godsend. I handle everything else, but having her makes projects go so much more quickly and our clients are so appreciative. After the project is done, we have a team of 3 (including our writer) that handles the SEM and social media. They do a great job. They also closely monitor Analytics and give full reports.

 

Occupy Greensboro

Occupy Greensboro:

http://occupygreensboro.org/

This site had to be built QUICKLY so yes, it is a template theme. I will probably be able to customize the CSS more as time goes on but the focus on this site was on functionality. It has a BuddyPress system that allows it to act as a stand alone social network but also integrates with Facebook. Also imperative was full web 2.0 integration as soon as this site was created. As the movement carries on it will become a great funnel for media and resources to help people understand what’s going on in our country and connect with each other so we can hopefully learn new ways to create better lives for ourselves. We are taking our futures back.

 

I have a few other sites built out, but their still on test domains for now so I won’t link them up. I’ll provide a list of links for the sites in the previous blog post eventually – I’m actually going to rebuild my portfolio galleries at some point this year hopefully.

I’m also looking for a developer with WordPress experience and a knack for jQuery to help me out. I’d rather have someone with programming skills than design skills so email me links to work samples if you are interested in working with me as a freelancer.

Brose the Archives

Tweets