Custom Permalinks with additional values – still 404 after rewrite flush
-
I am really having trouble setting up a custom permalink structure for two custom post types. short explanation:
Property – has custom taxonomy ‘property-location’
Apartment – has ACF relationship field to choose a property the apartment belongs to
So what I want is for the url to display:
property: /all-locations/%location%/%postname%
apartments: /all-locations/%location%/%property%/%postname%As the second one is more complicated, here is what works for the link:
add_filter('post_type_link', 'apartments_permalink_structure', 10, 4); function apartments_permalink_structure($post_link, $post, $leavename) { $post_id = $post->ID; if ( false !== strpos( $post_link, '%property%' ) ) { $property = get_field('property_relation', false, false); $locations = get_the_terms( $property, 'property-location'); $post_link = str_replace( '%location%', array_pop($locations)->slug, $post_link); $post_link = str_replace( '%property%', get_post_field('post_name', $property), $post_link ); } return $post_link; }
However, even after flushing rewrite rules, changing permalinks settings in backend and even hard-core flush it from the database, I get only 404 page. In the backend the correct permalink is visible, but somehow the theme now doesn’t recognise that it is a single-apartment.
What do I need to do to make it visible again?
BTW same on single-property – permalink is correct but single display not working…
- The topic ‘Custom Permalinks with additional values – still 404 after rewrite flush’ is closed to new replies.