Ended up with commenting out line 4 and changing the filter into this:
add_filter('post_type_link', function ( $post_link, $post, $id = 0 ) {
if ( 'project' != $post->post_type || 'publish' != $post->post_status ) {
return $post_link;
}
$post = get_post($id);
if (is_object( $post ) && $post->post_type == 'project' ) {
$terms = wp_get_object_terms( $post->ID, 'department' );
if($terms) {
return str_replace( 'project' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}, 1, 3);
Now pages works like they should again. All is well!
Related Posts:
- Custom taxonomy in URL showing 404
- Post type Permalink
- Rewriting a custom-post-type permalink with taxonomy term?
- Getting hierarchical custom post type permalinks to work just like pages
- Add .html (dot HTML) extension to custom post types
- Multiple post types – share same ReWrite slug?
- Custom post types – Use post_id in permalink structure when using has_archive => true
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- Using /%postname% for a custom post type
- Changing the URL Structure of a Paginated Custom Post
- How to modify URL structures in custom post types and taxonomies or terms
- Adding meta values to permalink
- Hierachical Custom post types permalinks not working
- How can i avoid the permalink start with ‘blog’ while using the custom post type?
- Custom Posttype Inheritance (and url structure)
- Permalinks so that one custom post type appears to be a child of another, not working
- Create permalink structure for one taxonomy archive per custom post type
- Slug for custom post type archive
- Custom permalinks
- Permalink rewrite with custom post type and custom taxonomy
- Custom post type permalink changing itself every other change
- Make permalinks based on an ACF-field
- Custom post type’s get_permalink returns wrong url
- Prepend meta_value to permalink of post
- Custom Permalinks for Custom Post Types and Taxonomies
- Removing parent slug from URL on custom post type
- URL rewrite and navigation structure for wordpress custom post type
- Removing CPT slug from URL results in 404 error for archive page
- How to rewrite custom post type URL for multiple depths instead of one specific depth
- Custom post type category, taxonomy and URL rewrite problem
- how to use two permalinks for one custom post type
- Rewrite on custom post type permalink not working?
- WordPress Rewrite rule for nested post types
- Custom Permalink Tag breaks Pagination
- Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks
- Permalinks for Taxonomy and Custom Post Type
- custom post type and custom taxonomy url conflict
- Share parent path between Custom Post Types and Pages?
- multiple url slug for single custom post type
- Custom Post Type and Custom Taxonomy Permalinks
- remove permalink “front part” for custom post type
- Change Permalink Structure for Tag.php template
- Add archive slug to default post post type
- Custom Post type and permalink settings
- Rewrite rules for custom posts types
- How to change custom post type permalink structure
- Adding custom post category slug in permalink causes 404 error for pages and posts
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- How Can I Change the Custom Post Type Slug to the Taxonomy Slug in the URL?
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- Custom post type as home page with custom url
- Customize Custom Post Type URL
- Custom post URL 404 error
- URL rewrite add author as base
- Set a CPT slug as a base name for all the taxonomies
- Custom taxonomy returns 404
- Parent Page and Breadcrumb URL’s for Custom Post Types Not Working
- CPT’s with landing page instead of archive – Url Rewrite?
- Custom post type permalink tag 404
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Hierarchical permalinks for custom post type and taxonomy
- Pretty URLs and custom post types
- Lost of query parameter when using permalink
- Best way to specify “article type” in URL
- Problems with 404, .htaccess, permalinks and WordPress custom posts locally on Snow Leopard
- How to have permalink like domain.com/term/postname?
- Combine multiple CPT names to create valid permalinks
- Set parent for custom post type archive rewrite url
- Custom post type permalink returns 404 when set to private
- Dynamic CPT permalink structure based on ACF field value
- Custom post type slug 404
- How to filter a custom post type by custom taxonomy without 404
- Custom Post Type nest under a normal WordPress Page
- Permalink Trouble with custom post types
- Permalinks not working (404) for the ‘item’ post type
- custom posts permalinks url rewriting
- Use a different URL path / permalink for CPT
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- I want to rewrite the URL of a specific post with a specific custom field to easily analyze in Google Analytics
- Rewrite URL for CPT to domain/post-name/post-id
- Custom permalink structure for custom post types including multiple taxonomy
- Custom post shows 404 after theme change
- Permalinks: custom post type -> custom taxonomy -> custom sub taxonomy -> post
- Pretty Permalinks with CTP and Taxonomies / Hierarchical
- Customise Permalink Structure For Custom Post Types
- How to make “single post” permalink maintain it’s sub-page structure
- Some permalinks on Apache/localhost development setup return 404’s when set to anything other than plain permalinks
- Two CPT: one is using part of the custom rewrite slug from the other
- Remove sequential number from permalinks
- Customizing the custom post type permalink
- URL Rewrite Adjustment for Custom Post Type causes template to revert to index.php
- Parent cpt/child custom post type URL permalink relationship
- Custom Post Type – Rewrite slug [duplicate]
- How can you preserve URLs when moving posts to a custom post type?
- Rewrite rules for using the same base slug for multiple content types
- 404 Error On Custom Taxonomy Pages 2, 3, etc
- Custom post type Premalinks main page and details page
- What is the best way to relate different custom post types?
- Allow child pages with the same base as the CPT slug