Custom Post Type only working when Logged in (4 posts)

  1. davidsword
    Posted 5 years ago #

    You would not believe how long it took me to figure out the problem:

    I have a custom post type for events "temds10", when I'm logged into wordpress, you can see the single temds10 posts via it's url slug ?event=title_of_event, -- but, if I'm not logged (like my audience won't be) I'm hit with a 404 error. simply signing back in removes the 404 error, and shows the event.

    I'm having an impossible time finding out why this is. My register_post_type() is set up normal, but two things I noticed when troubleshooting:
    - if I set query_var to anything other than "event" every single thing on the site will 404.. as if wordpress is reliant upon it..
    - if I change "temds10" to anything else and add a new post, it works perfectly fine, and I can see single posts logged in or out.. but I've coded way to much to change that as a perm solution.

    that, to me, makes me think that something has gotten corrupt... but I haven't a clue what.. I searched the databases for anything "temds10" but nothing was written..

    $args_array = array(
    		'label' 			=> __('Events'),
    		'singular_label' 	=> __('Events'),
    		'menu_position' 	=> 5,
    		'public' 			=> true,
    		'show_ui' 			=> true, // UI in admin panel
    		'_builtin' 			=> false, // It's a custom post type, not built in
    		'_edit_link' 		=> 'post.php?post=%d',
    		'capability_type' 	=> 'post',
    		'hierarchical' 		=> false,
    		'rewrite' 			=> array("slug" => "event"), // Permalinks
    		'query_var' 		=> 'event', // This goes to the WP_Query schema
    		'supports' 			=> array('title', 'excerpt', 'thumbnail', 'editor')
    	register_post_type('temds10', $args_array);

    Does anyone have the vaguest idea what's happening here, and the route I should take to resolve it?

  2. Helen Hou-Sandi
    WordPress Dev
    Posted 5 years ago #

    Edit/update: I figured it out soon after posting this! It turns out that it has to do with meta capabilities not being automatically mapped. See: http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types

    Basically, you should define the capabilities array and give your custom post type its own capability_type. It may work to use the same capability_type/capabilities for multiple custom post types, but I haven't tried that yet.

    Also, I am using Role Scoper, so I did not need to do the actual mapping of capabilities. The latest beta of Role Scoper works with CPTs.


    I'm having exactly the same problem and so far haven't figured out what's going on. I do see a custom post type item in my database though, along with revisions and a trashed item. I wonder if it has to do with the capability_type or assigned roles?

    Maybe we can help each other - are you using the multisite feature? Plugins?

  3. elektronicat
    Posted 4 years ago #

    I'm having this problem as well, it boggles my mind why the custom post types are not being displayed on the front-end when not logged in the back-end/dashboard..
    anyone a solution? 'cause this is going nowhere..

  4. elektronicat
    Posted 4 years ago #

    Well, i discovered that deactivating the Role Scoper plug-in did the trick. I probably have to adjust some settings in the plug-in to make it work with the custom post types, but for the development stage i'm gonna leave it nice 'n deactivated for a while.

Topic Closed

This topic has been closed to new replies.

About this Topic