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

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

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

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

$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
@Jan Fabry true, if your db is consistent. ;-) – wyrfel Feb 22 '11 at 9:58
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 posting your answer, you agree to the privacy policy and terms of service.