• I’m having difficulty previewing draft posts from within custom post types. If I click the ‘preview’ button it just sends me to the front page of the site.

    If I create a custom post type with the custom post type ui plugin (instead of defining it manually in the functions.php file as I’m doing now) then I can preview them so I’m obviously missing something in the register_post_type declaration – i just can’t figure out what.

    My code looks like this:

    register_post_type( 'press_releases',
    		array(
    			'labels' => array(
    				'name' => __( 'Press Releases' ),
    				'singular_name' => __( 'Press Release' ),
    				'add_new_item' => __( 'Add New Press Release' )
    			),
    			'menu_position' => 5,
    			'public' => true,
    			'rewrite' => array('slug' => 'press-releases', 'with_front' => true),
    			'supports' => array('title', 'editor', 'excerpt', 'thumbnail' ),
    			'capabilities' => array(
    				'edit_post' => 'edit_press_release',
    				'edit_posts' => 'edit_press_releases',
    				'edit_others_posts' => 'edit_others_press_releases',
    				'publish_posts' => 'publish_press_releases',
    				'read_post' => 'read_press_release',
    				'read_private_posts' => 'read_private_press_releases',
    				'delete_post' => 'delete_press_release',
    			)
    		)
    	);

    The obvious get-out clause for this would be to define the the post types through the plugin but:

    1. I have around 10 post types already defined and it would be a total pain to re-create them.
    2. I need to assign separate user capabilities to each post type, something which the plugin doesn’t do.
    3. I’d really like to know for future reference.

    Thanks for your help

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter tbp278

    (@tbp278)

    Ok so after a bit of poking around I’ve managed to isolate the problem to the rewite rule in the declaration.

    'rewrite' => array('slug' => 'press-releases', 'with_front' => true),

    If I remove it, with permalinks turned off, then I can see the preview.

    I need the slug to read ‘press-releases’ rather than ‘press_releases’ so I’ve tried changing the post type name to ‘press-releases’ so that I don’t have to use the rewrite. Thats all good.

    But then as soon as I turn permalinks on it stops working again.

    My custom permalink structure is just ‘/%postname%/’ – maybe there’s something wrong with that?

    Anyone? Please? It’s the final problem I have before this site can go live 🙁

    First off you should never use /%postname%/ as the permalink structure. If your site gets to be of any size then it will create performance issues. Use a year or month as the leading item if at all possible. In fact using a static string like /blog/ before postname is another way to do it.

    Your code for the rewrite looks fine to me so I am guessing that it comes down to the rewrite rules. Does it work if you do /%category%/%postname%/? Any time you change the rewrite code you’ll need to visit the permalinks page again to update the permalink rules for WordPress.

    Thread Starter tbp278

    (@tbp278)

    Yeah i had /%category%/%postname%/ originally but I dropped the %category% to see if it helped. Thanks for the heads up on that though, the site will be pretty big so that might have got me in a bit of bother.

    I can’t use any permalink structure. Even if I use one of the common settings it stops preview working.

    Thread Starter tbp278

    (@tbp278)

    I’ve still not been able to figure out what’s going on with this.

    I’ve taken the code directly out of the plugin (which works) and replaced my code with that but it still doesn’t work. I can only think this is some weird bug that’s probably a one of type affair.

    To get around the problem I’ve written in the capability support into the plugin which I needed but wasn’t previously supported.

    Anyone found the solution to this? I have the same problem as tbp278

    Having this same problem, previewing custom post types does not use the defined custom post type template. Anybody have any insight on how to get around this hurdle?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Preview custom post type posts’ is closed to new replies.