Retrieve permalink structure of custom post type
-
Hi there
I have a question about getting the permalink structure of custom post types.
Because I use WordPress with its REST API and a Vue.js Frontend, I had to rewrite the preview link a bit to point to my frontend.I have a custom post type registered where I rewrite its slug:
'rewrite' => array('slug' => 'company/media/%year%','with_front' => false),
So my preview link looks like:
https://domain.com/company/media/2019/my-cpt-post-name/?preview_id=1272&preview_nonce=90af8799eb&preview=true
I prepare this by callingget_permalink($id);
which gives me that parthttps://domain.com/company/media/2019/my-cpt-post-name
.Which is all good.
But now if I add a new news post (My custom post type) I need the get it’s permalink strucutre to prepare the preview link like the one above.
Only in this case when calling
get_permalink($id);
this will return something like this:https://domain.com/?post_type=news&p=1283
As long as it is not published the
get_permalink($id)
will remain like this.
How could I possibly get the permalink structure of this custom post type?I know that I can call this:
$permalink_structure = get_option('permalink_structure');
But this will only give me the permalink strucutre of the default post and not of my custom post type.
So how could I getcompany/media/%year%
?Thank you in advance.
Cheers
- The topic ‘Retrieve permalink structure of custom post type’ is closed to new replies.