Our Wordpress website has a custom post type named "life".
For each "life" post , A specific custom field value "special" (true | false) is set.
I want to rewrite the URL only if the custom field value "special" is "true" so that I can easily filter only those posts with special=true in Google Analytics.
I don't want to change the post type itself.
I also considered adding the taxonomy name to the URL, but this affetcs other posts.
I don't want to change the URL of posts where the "special" value is NULL or false.
I am thinking about changing the permalink structure with a hook or something , or forcing parameters to be attached to the URL.
- URL examples I want to realize (
life-article
is slug name and "special" field is true)https://example.com/life/special/life-article/
https://example.com/life/life-article/?special=1
- If the post's "special" value is false or NULL , URL should be
https://example.com/life/life-article/
- Custom post type is set with the following plugin:
This is a permalink setting of "life" in Custom Post Type Permalinks.
- Permalink setting screen
https://example.com/wp-admin/options-permalink.php
- The post type is set by the following plugin:
- I tried the following hooks, but it didn't work because I guess it wasn't compatible with the Custom Post Type Permalinks plugin.
add_rewrite_rule
post_type_link
- The "life" posts have
%postname%
in the permalink. Is it possible to rewrite this to a URL like/special/%postname%/
?
- Since the Custom Post Type UI plugin is used to add the post type, I would appreciate it if you could tell me how to do it without using
register_post_type()
function. Or is it possible to overwrite the value set inregister_post_type()
?