1

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?

3
$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
}
|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
  • 2
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy