Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

add custom post type to web.config

Posted on 2014-01-30
5
246 Views
Last Modified: 2014-02-11
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.
0
Comment
Question by:moshik008
  • 3
5 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 39822007
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.
0
 

Author Comment

by:moshik008
ID: 39823251
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.
0
 
LVL 15

Expert Comment

by:eemit
ID: 39827546
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().
0
 

Accepted Solution

by:
moshik008 earned 0 total points
ID: 39838862
just needed to add %category% to permalink -grrrr. silly me
0
 

Author Closing Comment

by:moshik008
ID: 39849634
figured it myself
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to install BuddyPress on your self-hosted WordPress site It’s been called everything from “social networking in a box” to “Facebook without the terms of service,” but until Feb. 16, BuddyPress was a relatively unknown outside the WordPress MU…
WordPress can be pretty daunting, especially for a beginner, so I thought it might be a good idea to write an article to show how easy it is to get started in WordPress and to design a custom theme.  The first step is to check with your hosting comp…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question