Remove 'custom-cpt' from 'custom-cpt/post-title' from custom post types permalinks - wordpress

Lets say I have this custom post type: 'pt-services'
So, posts will have this kind of urls:
pt-services/post-one
pt-services/post-two
How is it posible to remove pt-services from the urls? So they look like:
/post-one
/post-two
I tried what suggested in here but didn't work...
Any thoughts?

Related

.htaccess: Rewite rule to change to Semantic URL Struture

I am trying to change the URL structure of a search filter using .htaccess from this:
/tours/?tour-type=guided&tour-destination=europe&tour-type=guided&tour-duration=17%2B&tour-season=2020
to this:
/tours/guided/europe/guided/17/2020
Obviously the search filter has many different options such as days, locations different types and the like, I know it's possible in .htaccess but its proving elusive to me.
In wordpress it's better to use add_rewite_rule function. In example below I assume that tours is custom post type so post_type=tours. You can put there page id, category slug or whatever you want.
Note that with this rule if you want to send only tour-season you have to send something for rest of variables.
function tour_add_rewrite_rules() {
add_rewrite_rule('^tours/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$', 'index.php?post_type=tours&tour-type=$matches[1]&tour-destination=$matches[2]&tour-type=$matches[3]&tour-duration=$matches[4]&tour-season=$matches[5]', 'top' );
}
add_action('init', 'tour_add_rewrite_rules', 10, 0);

WordPress post permalinks for multiple categories, tags and taxonomy terms

I'm creating a WordPress plugin and one of the requirements is that a custom post type (photo) with a custom taxonomy (photos) needs to generate multiple permalinks if the post is assigned to multiple terms... so for example if a post is assigned to two taxonomy terms ("birthday" and "wedding") both of the following permalinks should display the post:
/photos/bithday/photo/post-name
/photos/wedding/photo/post-name
I currently have the following rewrite rule defined, which is returning a 404:
add_rewrite_rule( 'photos/(.*)/photo/(.*)?', 'index.php?post_type=photo&taxonomy=photos&term=$matches[1]&pagename=$matches[2]', 'top' );
However, if I visit the following URL which matches the pattern of my rewrite rule:
/index.php?post_type=photo&taxonomy=photos&term=birthday&pagename=post-name
It returns the correct content, but only after redirecting to this URL:
/photo/post-name/?taxonomy=photos&term=birthday-cakes
I must be missing something, any help would really be appreciated!
I managed to get this working by changing &pagename= to &name=.

Wordpress custom post type in wrong taxonomies

I've add a custom post type with custom taxonomies. I've also added rewrite rules in order to handle following urls:
courses/languages/english/english-course
where courses is the base slug, languages and english are taxonomy slugs and english-course is my custom post. english-course is a child taxonomy of languages and english-course has been categorized in english-course.
My rewrite rule is:
courses/(.+)/(.+)/(.+)/?$ => index.php?thr_course=$matches[3]
Everything works fine but any categories are permitted using this syntax. All following urls are legitimate and work as well:
courses/languages/french/english-course
course/products/english/english-course
course/anycategory/anycategory2/english-course
My rewrite rule is pretty obvious: it only matches my post name ignoring which categories it belongs to.
Where and how should I implement a check in order to return 404
if post exists but parent taxonomies are wrong?
I think WordPrss will not give you a solution for your customization automatically. Fetch other parameters from like parent / child category from URL, similar to thr_course parameter. Use this parameter in your query to narrow down your result.
Hope this will help you.

Wordpress ignoring custom permalinks structure

I have a custom structure for permalinks (Wordpress 3.9.1 + Types 1.5.7) like this:
/%post_id%
But wordpress returns me something like this:
/post-type/%postname%
It seems like wordpress overwrites my post_id param. Any idea?
Try this :
/%post-type%/%postname%/
If that doesn't work check the codex Wordpress codex
I'd also look into using tags, categories, or taxonomies as a possible solution (again, check the codex-I've got no idea)

WP Rewrite - Add post ID to URL

I have a custom post type (job) in my WordPress theme.
Posts of this type are inserted by users themselves, but if two or more jobs are inserted with the same title, the slug will be:
www.mydomain.com/job/title-choosen-by-user
www.mydomain.com/job/title-choosen-by-user-2
www.mydomain.com/job/title-choosen-by-user-3
...
Is it possible to keep the same slug and add the post ID in the URL using any rewrite? The result would be:
www.mydomain.com/job/100/title-choosen-by-user
www.mydomain.com/job/101/title-choosen-by-user
www.mydomain.com/job/102/title-choosen-by-user
...
Any help would be appreciated.
Thank you
Perhaps try changing your permalink structure in Settings > Permalinks under the WP admin dashboard.
Try:
/%post_id%/%postname%/
Ok I found a small but working tutorial for custom permalinks structure
http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2

Resources