• Resolved guitavares

    (@guitavares)


    I am developing a theme for a Soccer Team website.
    For that I created a Custom Post Type called ‘player’.
    For the player type only, I added some custom metaboxes to save the player height, weight, age, etc.

    It was all working fine until today I went to the regular PAGES Edit Screen, and after I updated a page, the screen came back with all the custom metaboxes that should appear only on the Player Screen (and it was before).

    Please somebody help me on how can I turn it back the way it was. I haven’t changed anything on my custom metabox declaration in functions.php

    thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter guitavares

    (@guitavares)

    UPDATE

    just in case I haven’t been clear before. The custom meta boxes appear only on my custom post type edit screen, until I update any PAGE. Then, they all show up in all the regular Pages editor.

    I just removed all my custom creations, deleted all custom metas from the database, went back to admin and updated a page. Everything ok.

    then I created back the custom types and boxes, went to admin and the boxes were showing only inside the custom post type, until I just updated any Page and all the metaboxes came back to the screen after the update.

    I also updated a POST and the same thing happened, the custom boxes appeared just after the update 🙁

    Thread Starter guitavares

    (@guitavares)

    OK I think it is solved:

    the issue was that I was using this to save the metaboxes values:

    add_action('save_post', 'player_savemeta');
    
    function player_savemeta(){
    	global $post;
    	update_post_meta($post->ID, 'name', $_POST['name']);
    	...etc...
    }

    The problem is that it was running the function for all posts saving actions, and so creating the custom boxes for every post.

    The solution I found (not tested yet) is to check the post type before saving the metadata:

    function player_savemeta(){
    	global $post;
    	if (get_post_type($post) == 'player'){
    		update_post_meta($post->ID, 'name', $_POST['name']);
    		...etc...
    	}
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Metaboxes for Custom Post Type are showing on regular Pages Editor’ is closed to new replies.