2

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?

1 Answer 1

4
$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
}
3
  • If you use name you will get at most one result, so the break is not needed.
    – Jan Fabry
    Commented Feb 22, 2011 at 9:17
  • 1
    @Jan Fabry true, if your db is consistent. ;-)
    – wyrfel
    Commented Feb 22, 2011 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
    Commented Nov 14, 2012 at 3:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.