Link to home
Start Free TrialLog in
Avatar of moshik008
moshik008

asked on

add custom post type to web.config

Hi all,

I have a problem with permalinks:
I have 2 sites with permalink sets to the "pretty" post-name settings for exaple:
http://www.mydomain.com/sample-post/

i am on windows servers on both sites so I updated the web.config file as suggested all over the internet, posts and pages works as expected, but on both sites i have custom post types and eg.
http://www.mydomain.com/movies/sample-post/ 
dosen't work.
I know that wordpress and windows servers are not working together all so good, but it is what my customers wants.
i suppose I must add some sort of rewite to the web.config, but i dont know how, can someone can help with the sample code for it.

thanks.
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

If you have permalinks working for normal posts, then it should also work for custom post types...as far as web.config is concerned, there is no difference between the two things.

I almost want to say you don't have the slugs for the custom post types set up correctly in the CPT definition code.
Avatar of moshik008
moshik008

ASKER

I doubted because both of the sites based on very well known templates (different ones), so I suppose that the slugs are all in place.
If your custom post type creation is in a plugin try to use template_include filter:

add_filter( 'template_include', 'your_prefix_include_template_function', 1 );

Or from a class:
add_filter( 'template_include', array( $this, 'include_template_function' ), 1 );

In this function return your custom post type template path.


You should also take a look at:
- 'template_redirect' action hook
- Rewrite API, 'generate_rewrite_rules' action hook
- and at Rewrite endpoints API (function add_rewrite_endpoint())

but don't forget this tips:

Always refresh your Permalink Settings after you have changed rewrite slug by
Custom Post Types or Custom Taxonomies:
Dashboard/Settings/Permalink Settings, just save it again.

To automatically flush your rewrite rules use the function flush_rewrite_rules().
ASKER CERTIFIED SOLUTION
Avatar of moshik008
moshik008

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
figured it myself