WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have multiple plugins with different post_type(s). When I save or publish, all of the custom_post_meta that belong to one specific post_type are also saving.

I'd like to filter by post_type so that the custom_post_meta will only save in a specific post_type.

So my question is, if you have multiple plugins:

How do you save a specific postmeta to a specific post_type?

Would you just say:

if (post_type=="my_post_type") {

And how do you get the post_type value?

share|improve this question
up vote 2 down vote accepted

Do the check inside the callback. save_post will pass you both the post ID and the post object:

do_action('save_post', $post_ID, $post);


function save_my_meta_box_to_postmeta($post_ID, $post) {
  if ('yourtype' === $post->post_type) {
    echo '<pre>';
    echo '</pre>';

You may want other conditionals as well like !DOING_AJAX, for example.

share|improve this answer
I kept on targeting save_post, edit_post, and publish_post. Does not work. In my observation, do_action('save_post',$post_ID,$post) only seem to be applicable if $post_ID and $post are given inside the variable of wp_insert_post function. By not working, I mean $post->post_type does not seem to return any value inside save_post when used in a conditional statement. – Franz Noel Jul 9 '13 at 22:40
Awesome... it finally worked! I made sure that $priority and $accepted_args inside add_action were populated. Then, everything went well. Thanks. – Franz Noel Jul 9 '13 at 23:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.