php - WordPress 'post_name' in posts table duplicated
I'm trying to receive all portfolio entries from the database. I want to list this and also link the WordPress path to it. This is the SQL query:
SELECT id, post_title, post_name FROM 1bncopo2_posts WHERE post_type='portfolio';
post_title could be the following:
- Mercedes-Benz AMG C63
- Mercedes-Benz S500
- BMW 650i XDrive
and now post_name for the first entry of the above list ismercedes-benz-amg-c63
. However, I found that in my database table, multiple portfolio vehicles (even vehicles by BMW, etc.) havepost_name
set tomercedes-benz-amg-c63
. My idea was to generate the URL to the portfolio item usingpost_name
as an appendix to the wordpress path. TO BE CLEAR: This is going to be a seperate application reading from the WordPress installation's database and trying to make up the corresponding links to the portfolio items.
Now thatpost_name
is notUNIQUE
or something I could use, I have two questions:
- Why would the WP database allow for duplicated
post_names
? - How can I get the post (portfolio)'s URL, if not by
post_name
?
Answer
Solution:
It is impossible to repeat the link, if you see the link from the beginning you will find it different.
If this post
(mercedes-benz-amg-c63)
for custom post type called(portfolio)
you see URL like:But if its post type (post) you see URL like:
Then as you see the URL not duplicated