Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom field called "song-id" and I'd like to lookup a post by a song-id value. Can someone give me the code snippet for it?

(bonus: also looking for a code to use the permalink in the post to redirect to that page)

share|improve this question
add comment

1 Answer

$songQuery = new WP_Query('meta_query' => array(
    array(
        'key' => 'song-id',
        'value' => 'song id value here',
        'compare' => '='
    )
));

You can use above code to query with custom field then use loop to get the contents.

share|improve this answer
1  
If it's just one key then you can directly use meta_key and meta_value_num –  Rutwick Gangurde Jul 31 '12 at 5:40
    
yes but it's better to use meta_query i think –  Yalamber Jul 31 '12 at 5:41
    
Indeed it is! ;) –  Rutwick Gangurde Jul 31 '12 at 5:43
add comment

Your Answer

 
discard

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.