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.

When I try to use get_page() function I get the error message:

Only variables can be passed by reference

 

But what doesn't make sense is that I can use a work around that blows my mind:

First test

$test1 = get_page(49);

Returns error message

Only variables can be passed by reference

 

Second test

$page = get_page_by_title( 'About' );
$test2 = get_page($page->ID);
echo 'ID:'.$page->ID.' Post title: '.$page->post_title;

Returns no error

ID:49 Post title: About

 

Can anyone shed some light on what I'm doing wrong?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Correct to your first test:

$id = 49;
$test = get_page( $id );
share|improve this answer
    
Cheers, feeling a bit silly right now :) –  jamiers May 5 '12 at 17:09
    
@jamiers Do not think about the bad, you are probably tired .. –  user15194 May 5 '12 at 17:17
add comment

You're seeing the expected behavior of the get_page() function. From the function's codex page:

$page_id = 123; // 123 should be replaced with a specific Page's id from your site, which you can find by mousing over the link to edit that Page on the Manage Pages admin page. The id will be embedded in the query string of the URL, e.g. page.php?action=edit&post=123.

$page_data = get_page( $page_id ); // You must pass in a variable to the get_page function. If you pass in a value (e.g. get_page ( 123 ); ), WordPress will generate an error. By default, this will return an object. [Emphasis added]

So just save the page_id as a variable and pass it in (as the other answer suggests).

share|improve this answer
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.