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 added some fields to a custom post type through

function add_electric_portfolio_box() {
                "electric_portfolio_info", __('Detalles de la web'), "electric_portfolio_fields", "electric_portfolio", "normal"

Which I then call with:

add_action('admin_init', 'add_electric_portfolio_box');

But now those custom fields appear in regular pages too. Is it posible to show those fields ONLY on that type of post?

Here is a screenshot of the undesired fields in the regular pages Undesired fields

as opposed to the desired fields in the custom post: enter image description here

share|improve this question

Sure, just check the post type of the post you're on.

global $post; // make sure $post is available
if( get_post_type( $post ) == 'your_custom_post_type's_name' ) {
    add_meta_box( ... );

UPDATE: I think the $post variable might not have been getting passed to get_post_type.

share|improve this answer
get_post_type returns false. Maybe it is because of the way I add the meta box? (Check out my edits) – Cmorales Jul 24 '12 at 20:11
Try the updated snippet. – mrwweb Jul 24 '12 at 20:47
I keep getting false :S By the way... I add the post type on a plugin, maybe that's the reason? – Cmorales Jul 25 '12 at 13:26

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.