• Resolved tbp278

    (@tbp278)


    Hey,

    I’m going out of my mind with setting up custom post types with pretty permalinks on wp3. It seems no matter what I try a 404 page is thrown up whenever custom permalinks are turned on.

    I’ve created a post type called ‘videos’ with the following code:

    add_action('init', 'post_type_videos');
    
    function post_type_videos() {
        $args = array(
            'label' => __('Videos'),
            'singular_label' => __('Video'),
            'public' => true,
            'show_ui' => true,
            'hierarchical' => false,
            'query_var' => false,
            'menu_position' => 5,
            'capability_type' => 'post',
            'rewrite' => true,
            'supports' => array('title', 'thumbnail', 'editor')
            );
    
        register_post_type( 'videos' , $args );
    
    }

    and a custom permalink structure of simply: /%postname%/

    Even if i use one of the default permalink settings it won’t work, but then if I turn them off everything bursts into life…

    Can anyone shed any light on what I’m doing wrong?

Viewing 15 replies - 1 through 15 (of 15 total)
  • This any use?

    http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress

    rewrite

    The rewrite argument allows you to define the permalink structure of your posts when viewing the single post. For example, you may want to have a structure like yoursite.com/cool/post-name. WordPress will set up a default structure based on your taxonomy name. The rewrite argument can be set to true, false, or an array of values. It takes two arguments:

    * slug: The slug you’d like to prefix your posts with.
    * with_front: Whether your post type should use the front base from your permalink settings (for example, if you prefixed your structure with /blog or /archives).

    ‘rewrite’ => array( ‘slug’ => ‘cool’, ‘with_front’ => false ),

    Thread Starter tbp278

    (@tbp278)

    I’ve studied Justin’s article from top to bottom over the last few days and can’t find what I’m doing wrong.

    I’ve tried adding:

    add_action('init', 'post_type_videos');
    
    function post_type_videos() {
        $args = array(
            'label' => __('Videos'),
            'singular_label' => __('Video'),
            'public' => true,
            'show_ui' => true,
            'hierarchical' => false,
    		'rewrite' => array( 'slug' => 'video', 'with_front' => false ),
            'supports' => array('title', 'thumbnail', 'editor')
            );
    
        register_post_type( 'videos' , $args );
    
    }

    but to no avail…

    Do other URLs work ok under a custom permalink, ie. do permalinks work aside from custom post type URLs.

    Sounds to me (correct me if i’m wrong) like permalinks aren’t working full stop, as opposed to just post type permalinks not working.

    Thread Starter tbp278

    (@tbp278)

    Sorry, I should have mentioned that:

    Normal posts weren’t working, but I’ve figured that out and they’re all good, it’s just custom post types that 404 now

    Thread Starter tbp278

    (@tbp278)

    Ah here’s something weird:

    If i register a custom taxonomy with the same name as a custom post type, the options on the taxonomy seems to over ride the options on the post type.

    ie. I have a ‘videos’ taxonomy registered like so:

    register_taxonomy('videos', array( 'videos'),array( 'hierarchical' => true, 'label' => 'Videos','show_ui' => false,'query_var' => 'videos','rewrite' => array('slug' => 'videos'),'singular_label' => 'Video') );

    if i turn the ‘rewrite’ value to false on the custom post type it doesn’t make any difference until I remove the videos taxonomy.

    Is this something which I shouldn’t be doing? I do have a pretty complicated reason for naming both custom post types and taxonomy the same (mainly due to auto creation of a taxonomy term when a custom post is added)

    Have you tried stipping it down to the bare minimum code i.e. leaving out as many arguments as possible, whatever their defaults are, and seeing if the custom permalinks work then?

    Or maybe putting it in the same format as Justin?

    add_action( 'init', 'create_my_post_types' );
    
    function create_my_post_types() {
    	register_post_type( 'super_duper',
    		array(
    			'labels' => array(
    				'name' => __( 'Super Dupers' ),
    				'singular_name' => __( 'Super Duper' )
    			),
    			'public' => true,
    		)
    	);
    }

    Hard to say, but i’d guess at there being a conflict between the two sets of rewrite rules..

    Try giving one of them, either the post type or the taxonomy an alternative rewrite slug, and see if things then start to behave..

    http://codex.wordpress.org/Function_Reference/register_post_type
    http://codex.wordpress.org/Function_Reference/register_taxonomy

    See the rewrite parameter, accepts an array, try providing an alternate slug.

    Thread Starter tbp278

    (@tbp278)

    Yep – i tried copying Justins code exactly, pasted it into my functions.php and…

    404 AGAIN! I’m going mad.

    Are you saving your permalinks after adjusting the code?

    When i’ve registered post types and/or taxonomies, permalinks did need to be saved before the appropriate URLs functioned.. (have you been doing the same?)

    Thread Starter tbp278

    (@tbp278)

    ooookay, I’m getting closer.

    I think the problem lies with the custom post type and custom taxonomy sharing a query_var.

    I’ve never really understood qhat query_var does? But i guess it makes sense not to have two variables named the same 🙂

    So at the moment I’ve stripped out all my stuff and just used justin’s example, just with the added custom taxonomy:

    function create_my_post_types() {
    	register_post_type( 'super_duper',
    		array(
    			'labels' => array(
    				'name' => __( 'Super Dupers' ),
    				'singular_name' => __( 'Super Duper' )
    			),
    			'public' => true,
    					)
    	);
    
    	register_taxonomy('super_duper', 'super_duper', array('hierarchical' => true, 'label' => 'Super duper stuff', 'show_ui' => false, 'query_var' => 'super_duper_tax', 'rewrite' => array( 'slug' => 'super_duper')) );
    
    }

    It seems that its fine to name them the same but if the query_var is the same it 404’s.

    Now, i need to get that working with my post types…

    Hi tbp278! Try using a more complex permalink structure, that seems to have solved my problems. I described my progress in greater detail in this post.

    Edit: I just realized you had already solved you problems. Anyhow, hope I can help someone out there running into the same problems I did.

    Hey tbp278, I just found this support thread because of the exact same problem.

    It does appear that its an issue having Custom Post Types and Custom Taxonomies that have the same name. I had ‘Portfolio’ for both and the posts where 404’ing, I’ve just changed the taxonomy to ‘Work’ and the posts are now working fine.

    I solved my 404 problem with custom post types by re-saving the permalinks in the wordpress backend.

    Hope this helps some of you.

    I’ve been beating my head on this one for the past hour. Turns out that my issue was plugin related. Always good to keep that in mind.

    onepack – thanks… this helped me.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Custom post types permalinks 404’ is closed to new replies.