Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a site with urls like so: site.com/folder/page-name

It is moving to another site built in wordpress and I am trying to recreate the page to ensure incoming links continue to work as normal.

The posts are organised into different custom post types, but essentially they will display from the same page, so I have created a new page called old_content.php and I want to use this to display content from incoming links.

I have created the page in wordpress using old_content.php as the template. When I load site.com/folder/, I can correctly see my old_content.php file.

In old_content.php, I will wp_query the data for the page using the third url segment, e.g. site.com/folder/my-page-name. As soon as I add my-page-name, it 404's.

How do I stop it from 404'ing so I can query the db and display the content?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

When you add a custom post type, WordPress doesn't know that it needs to regenerate it's permalinks/rewrite rules.

Visit the permalinks settings page to flush and regenerate the links and your custom post type permalinks will start to work, else you'll get 404 messages.

A word of warning: Some people will advise you call flush_rewrite_rules on the init hook. While this will work, it will also greatly slow down your site, and cause other unpredictable problems.

Changing your post type URLs

This can be done using the rewrite parameter in register_post_type:

http://codex.wordpress.org/Function_Reference/register_post_type#Arguments

rewrite (boolean or array) (optional) Triggers the handling of rewrites for this post type. To prevent rewrites, set to false. Default: true and use $post_type as slug $args array

  • 'slug' => string Customize the permastruct slug. Defaults to the $post_type value. Should be translatable.
  • 'with_front' => bool Should the permastruct be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true
  • 'feeds' => bool Should a feed permastruct be built for this post type. Defaults to has_archive value.
  • 'pages' => bool Should the permastruct provide for pagination. Defaults to true
  • 'ep_mask' => const As of 3.4 Assign an endpoint mask for this post type. For more info see Trac Ticket 19275 and this Make WordPress Plugins summary of endpoints.
    • If not specified and permalink_epmask is set, inherits fro permalink_epmask
    • If not specified and permalink_epmask is not set, defaults to EP_PERMALINK

e.g.

'rewrite' => array( 'slug' => 'freetips' ),
share|improve this answer
    
Tried that, it is now redirecting to the custom post type slug. I dont want it to do this so i added remove_filter('template_redirect', 'redirect_canonical'); which has stopped that. But it is still returning the 404. –  BillyKhan Mar 19 '13 at 11:44
1  
Can you post the registration code for all taxonomies and post types in your question, along with expected URL and actual URL so I can see the difference. Also remove that filter call that removes redirect_canonical, it's redirecting you to the actual URL, not away from it –  Tom J Nowell Mar 19 '13 at 11:58
    
pastebin.com/8Ctr1ShE This is my post types code, taxonomies are done using a plugin. So I want /freestuff/my-tip-page and /freetips/my-stuff-page to display under /free/my-tip-page and /free/my-stuff-page as /free/blah are how all incoming links are. Hope that makes sense. –  BillyKhan Mar 19 '13 at 12:09
1  
I don't see what you've been doing to try and change the URLs, as they won't automagically work without doing anything, you need to tell WordPress to use a different URL structure via the rewrite option –  Tom J Nowell Mar 19 '13 at 12:34
    
Just tried using wp_rewrite and got it working. Was trying using htaccesss rewrites without luck. Thanks for the help! –  BillyKhan Mar 19 '13 at 12:37
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.