WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using wp_query() to get custom posts from the database. I want to list these out as links to the entries, so I'm thinking I could use the slugs. Sadly these don't seem to be included in the wp_query object.

Here's my code:

    $oWP = new wp_query(array(
        'post_type' => 'letters_of_ref'
        , 'orderby' => 'meta_value'
        , 'meta_key' => 'aaaConsultant_dateofletter'

So, given the post ID, how do I get the post's slug?

Alternatively, am I going down the right path to construct the link?

Update: just found the get_permalink() and the_permalink() functions, so I'm good for the link. Still want to find the slug though.

share|improve this question
OK, so I just ran across an unrelated question which mention get_permalink() and the_permalink(), which are the recommended ways of getting the post's link. Still, how do I get the slug, given the ID? – NotoriousWebmaster Apr 21 '13 at 0:04
up vote 1 down vote accepted

The slug is already in the post object, it's $post->post_name.

And as you observed, yes, the way to get the post link is get_permalink( $post->ID );

share|improve this answer
Thanks @brasofilo. I had the whole object in front of me, but I was looking for something that said slug. – NotoriousWebmaster Apr 21 '13 at 0:14
I didn't remember post_name as well, searched for slug in the core and found it :) – brasofilo Apr 21 '13 at 0:15
Thanks for that. Don't feel like such a n00b. Also, I have to start looking in core as well. – NotoriousWebmaster Apr 21 '13 at 0:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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