Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a arbitrary string and want to check if a post with that slug string exists in the site. I tried to find a way to list all slugs, but can't find such a thing. Thanks

share|improve this question

2 Answers

Do you mean post slug? You can try to make use of wp_unique_post_slug() that WP uses to generate those. If I remember right if slug you are trying to use is not unique it will be returned with numerical index appended.

share|improve this answer
sorry to reply so late. Yes post slug is the slug I want. Unfortunately I don't have the post_id which is required to use wp_unique_post_slug() – lulalala Aug 22 '11 at 1:43
$args = array('name' => $slugName, 'post_type' => $postType); 

$slug_query = new WP_Query($args);
echo "<pre>";
var_dump($slug_query);
exit;

You then have more than enough information to test if a post was returned or not, hope this helps.

share|improve this answer

protected by Community Apr 10 at 12:42

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.