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.

In the theme there is a custom post type called faq

I just want to get certain post by its name (NOT by id cause no id exist).

<?php query_posts('post_type=faq') ?>

how to get the_tile() and the_permalink() by its name?

share|improve this question
add comment

migrated from stackoverflow.com Feb 22 '11 at 2:58

This question came from our site for professional and enthusiast programmers.

1 Answer

$posts = get_posts(array('name' => 'your-posts-name', 'post_type' => 'faq'));
foreach ($posts as $post) {
    $title = get_the_title($post->ID);
    $permalink = get_permalink($post->ID);
    break; //use this to limit to a single result
}
share|improve this answer
    
If you use name you will get at most one result, so the break is not needed. –  Jan Fabry Feb 22 '11 at 9:17
1  
@Jan Fabry true, if your db is consistent. ;-) –  wyrfel Feb 22 '11 at 9:58
1  
foreach loops are for iterating. Since you are not iterating and instead just using the first item in the array, it makes more sense to do $post = $posts[0]. –  cdmckay Nov 14 '12 at 3:07
add comment

Your Answer

 
discard

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