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?
$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
}
name
you will get at most one result, so the break
is not needed.
Commented
Feb 22, 2011 at 9:17
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]
.