Solved

add custom post type to web.config

Posted on 2014-01-30
5
235 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

How to create your own WordPress Theme Before I begin with the theme design tutorial, I would like to give you the basics of what is required to make a WordPress Theme. The most basic WordPress theme only requires 2 files: a style.css file and an…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now