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.

On one of my page templates I need to include the contents of several other pages. For example, if my page template is called Fruit, I need to pull in page content from pages named Apple, Pear, Orange, Lime, etc. This gives my user the ability to edit Apple and Lime individually from admin area.
I'm trying to use get_page_by_title() to pull in these sub pages, but that function only seems to want to work once per page. The first time I call

get_page_by_title('Apple')

works perfectly. When I later call

get_page_by_title('Lime')

it displays Apple again. Is this function limited to once per page, or am I doing something else wrong?

Edit: It seems that no matter what title I pass to get_page_by_title() it will always get the content of the current page. So if I'm on example.com/fruit and call

get_page_by_title('Apples')

with in the page, it will always display the content from Fruit. Not Apples.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

get_page_by_title returns an id not content. here is an example of what I use to get content from a certain page id.

call the function

$page_id = get_page_by_title('title');
$excerpt =  get_excerpt_by_id($page_id);

in functions.php

function get_excerpt_by_id($post_id) {
   global $wpdb;
   $query = "SELECT post_content FROM $wpdb->posts WHERE ID = $post_id LIMIT 1";
   $result = $wpdb->get_results($query, ARRAY_A);
   return $result[0]['post_content'];
}
share|improve this answer
    
Great. Thank you very much for the clarification. –  Jeff Jul 7 '11 at 19:14
    
get_page_by_title() returns post' object or one of numeric and associative arrays, containing post information, not post id. –  Max Yudin Jul 18 '12 at 11:38
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.