Additionally, do have a look at the register_post_type()documentation for all the juicy details.

Don’t Forget To Flush

This is Important (how very true…), after you add a custom post type you must do one of two things for the rewrite rules to start taking affect (so you can begin testing your custom post types and not get 404 headers).

WordPress will NOT auto refresh it’s rewrite rules on its own, you will have to do this by:

I recommend you do the first option, here is what WordPress has to say about the latter:

Keep in mind that the flush_rules function is quite slow, so in practice you never want to call it from the init filter that gets executed on each page load. Instead, call this function only when the rewrite rules change. If the rules get set up and then never change, it is enough to flush in register_activation_hook of your plugin.

So… What Does This Have To Do With Thesis?

By default Thesis will only add its custom meta boxes (SEO Details and Additional Style, Post Image and Thumbnail, Javascript and Multimedia Box Options) to “post” and “page” types. After adding your own custom post type, use the following to make the default Thesis meta boxes appear by also adding this to your custom_functions.php file:

What a laughable error on my part – I completely missed the first chunk of code; I read your comment – line 45. Wait, there’s no line 45.. What’s going on here??

Thanks Dimas!

Actually I’m really having a tough time getting the hang of writing custom posts and inserting fields in these posts… I’m trying to create meta boxes that show up on custom post types. I saw your other tutorial on custom posts + meta boxes but am having a tough time following – do you have a code that I could implement in thesis?

Will do! Thank you so much! If you have a minute and want to take a look over my code, I attempted to follow the “how to create a wordpress custom meta box” tutorial in conjunction with the “how to limit the display of a meta field” and also tried to incorporate this article –

here’s my error message:

Warning: call_user_func(my_meta_setup_3) [function.call-user-func]: First argument is expected to be a valid callback in /home/events/public_html/wp-admin/includes/template.php on line 2868

I used a plugin called Custom Post Types UI to create my custom post type. The plugin makes it very easy to manage custom post types. I waited to see if Chris added a way to have Thesis meta boxes in 1.8 but he just released it this morning and I’m not seeing the meta boxes. So, I added your code to add the custom meta boxes to my custom post type and it worked out great. Thanks for the tip Dimas!

I tried your code to add the Thesis Metabxes to my custom Posts. So far it worked like a charm.
But how can i make non Thesis Metaboxes (from plugins for exp.) show up in my custom post eidt Screen too???

I’ve added the code for the meta boxes on a custom post type on my development site. The meta boxes appear just as expected.

Unfortunately, changes to any of the added meta boxes do not save.

I’ve tracked the problem down to the save_meta() function in options_post.php. The data is not saving because it fails the nonce check (lines 146-150 of options_post.php)

// We have to make sure all new data came from the proper Thesis entry fields
foreach($post_options->meta_boxes as $meta_box) {
if (!wp_verify_nonce($_POST[$meta_box['noncename'] . '_noncename'], plugin_basename(__FILE__)))
return $post_id;
}

I know it fails there because I commented out that particular section for testing and the data saves fine when it is commented out. I, obviously, want to keep the nonce check in there, for security reasons.

Any thoughts?
I have doublechecked and have not strayed from what you have suggested, other than excluding certain meta boxes from displaying based on “$meta_box[‘id’]”
Which, now that I think about it, is exactly why it is failing.
The loop in options_post is going through all the default metaboxes
Since I have prevented some from being displayed, their nonce doesn’t exist on my edit page, so the nonce check fails for those missing boxes.

So, the question is, how do I display working metaboxes for only those metaboxes I want?

Rich, see line 56 to 59 in the article above, the loop goes through the meta boxes by name, do a var_dump() of the array and see what the names are, then create a custom array and only use the names for the meta boxes you want to appear.

I still don’t think that will work. I can easily choose the metaboxes I want to appear or not appear.
The problem is that in save_meta() in options_post.php, the loop is:

function save_meta($post_id) {
$post_options = new thesis_post_options;
$post_options->meta_boxes();
// We have to make sure all new data came from the proper Thesis entry fields
foreach($post_options->meta_boxes as $meta_box) {
if (!wp_verify_nonce($_POST[$meta_box['noncename'] . '_noncename'], plugin_basename(__FILE__)))
return $post_id;
}
...
}

$post_options->meta_boxes doesn’t have anything to do with what I have decided should appear on my edit page. Or am I missing something? Even if I create a custom array (as opposed to skipping the add_meta_box() function call based on the metabox name / id), that custom array doesn’t equal the array that is being looped through in save_meta() in options_post.php.

From what I understand, $post_options->meta_boxes will contain all of the metaboxes, regardless of what I have decided to display? So, the nonce will fail when the loop in options_post.php is on a metabox in $post_options->meta_boxes that is not in the set of metaboxes I have elected to display on my custom post edit screen.

If I include ALL metaboxes, as is coded in lines 56-59, the meta information saves fine. It only fails if I decided to exclude anything.

Unless the scope of $post_options->meta_boxes in save_meta() (options_post.php) is different than I understand?

As reference, here is the code I am using that does display the metaboxes I want, yet will not save/update the metadata entered into the metaboxes. If I remove the if statement (so, including all metaboxes), the meta data saves fine:

So, when creating the [expected-value], you need to use the same $action argument that the save_meta() function is using. Since my save_post action is called from custom_functions.php, and the save_meta() function is called from options_post.php, plugin_basename(__FILE__) will be different, and the nonce would fail.

So, I did some ugliness (hard coded the path to the options_post.php file) to make it work for now, but here it is:

Note: during all of this, I realized that line 61 of your original post is not necessary. The action to save meta data during save_post had already been called. It isn’t necessary to call it again.

I also removed line 48, adding the action to admin_menu. Instead, I call the function that adds the meta boxes via the ‘register_meta_box_cb’ argument of register_post_type, which is called during ‘init’

Rich, glade you got it all working, there typically is always a way to solve a problem, just have to look at it from different angles … in terms of your hard coded issue you may try the following an see if that creates an accurate nonce:

I know this post is nearly a year old now but I have a question that i can’t seem to find an answer to.

I have multiple custom post types and I wish to add the thesis seo and meta boxes to all of them but I get a repeat error when I do. The first is fine and works perfectly using the code above. Unfortunately I cannot find a way to duplicate this for my other custom post types. Can anyone shed some light on this?

Great tutorial. Stopped by your blog after hyperarts linked to you and definitely will be back. I do a lot with thesis and so these kinda things come in handy.
Kim
PS: You asked in another post about spam control. I’ve had trouble with spamfree so I rely heavily on GASP (growmaps anti spambot plugin) which works well for stopping bot traffic.

@Kim, thanks for your comment, I will definitely checkout GASP, spamfree worked really well, but recently has started to let more SPAM comments through (akismet still catches them, but just more for me to deal with).

Thanks very much for this. The menu showed up fine. I reset the permalinks. Now, I’m curious, since I didn’t CPT up when I first started (it’s a recipe blog), and now I’ve added a new ‘recipes’ CPT; do I just go in and transfer the content from the regular post type in to the custom recipe post type? And then erase original post?