Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

404 on Custom Post Type WordPress

Hi,

I did notice another similar thread about this type of problem but am still unable to solve this problem even after scouring various help topics around the web on the same problem.

So here's some background info:

I have a wordpress blog installed into it's own sub-directory (to keep the files neat and tidy),

i.e. www.mydomain.com/hotels/

After developing the site I then moved the .htaccess and index.php files to the root directory of my domain,

i.e. www.mydomain.com/

Now I have a custom post type called "hotel_desks" and I have a rewrite slug rule set to "hotels-near"

However whilst the following worked,

www.mydomain.com/hotels/hotels-near/<post-slug>

The following does not (since I moved the site)

www.mydomain.com/hotels-near/<post-slug>

I just get met with a 404 error.

I've updated my permalink structure to reflect,

/%category%/%postname%/

and my .htaccess file contains,

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>


My functions.php includes the following for the custom_post_type,

function create_my_post_types() {
register_post_type( 'hotel_desk',
array(
'labels' => array(
'name' => __( 'Hotel Desks' ),
'singular_name' => __( 'Hotel Desk' ),

),
'public' => true,
'menu_position' => 2,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
'rewrite' => array( 'slug' => 'hotels-near'),
'taxonomies' => array( 'post_tag', 'category'),
'menu_icon' => get_bloginfo('template_directory') . '/images/hotel_desk_custom_icon.png',
));
}


I have tried various 'rewrite' slug arrangements that include,

a) 'rewrite' => array( 'slug' => 'hotels-near', 'with_front' => FALSE,),

b) 'rewrite' => array( 'slug' => 'hotels-near', 'with_front' => TRUE,),

c) 'rewrite' => array( 'slug' => 'hotels-near'),

Just to test... but no dice..

Any thoughts?


Answers (2)

2011-05-08

David Navarrete answers:

hi, you have problem with wp_rewrite.

you could will try with this



function create_my_post_types() {
global $wp_rewrite;
register_post_type( 'hotel_desk',

array(

'labels' => array(

'name' => __( 'Hotel Desks' ),

'singular_name' => __( 'Hotel Desk' ),



),

'public' => true,

'menu_position' => 2,

'hierarchical' => true,

'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),

'rewrite' => array( 'slug' => 'hotels-near'),

'taxonomies' => array( 'post_tag', 'category'),

'menu_icon' => get_bloginfo('template_directory') . '/images/hotel_desk_custom_icon.png',

));
$wp_rewrite->flush_rules();
}


Wordpressing comments:

Hi David,

Thanks that does appear to work but is it OK to use the flush_rules in this manner? I've read that it's not recommended as it causes unnecessary load?

Also although that fixes the problem, I'd like to know exactly what's causing the problem with rewrite? Because it works in the initially setup (as explained above) but not when I move the .htaccess and index.php files.




David Navarrete comments:

because you need refresh de pretty links.

2011-05-10

Just Me answers:

Maybe in addition to what has been said you would want to take a look at this post http://wordpress.org/support/topic/writing-wp_rewrite-gtnon_wp_rules-to-htaccess. It is old but at the very end it has some information on rewrite but on every page load.