0

For some categories on my site there's introduction text that needs formatting (so using the category description isn't an option) and placing at the top of categories.php.

I've added a post ID to the category description field thinking I could then use get_post() to load the relevant post's content then list all the posts in the category underneath.

However it doesn't work and breaks the loop.

The error I get is

Fatal error: Only variables can be passed by reference in /wp-content/themes/pap_01/loop.php on line 39

and line 39 is

$secintro = get_post(439);
print_r($secintro);

I've tried resetting post data and rewinding the loop after this but nothing helps. And print_r($secintro); does show anything either.

1

You're using an old version of WordPress. Upgrade to 3.5 and you will no longer see that error.

Here's the function declaration for get_post in WP 3.4:

function &get_post(&$post, $output = OBJECT, $filter = 'raw')

Notice the ampersand in front of $post? That would mean the value is passed by reference. You can give the function a literal, it has to be the variable.

The correct solution is to update to WP 3.5 (we're on 3.5.1 at the time of writing). Get post to WP 3.5+:

function get_post( $post = null, $output = OBJECT, $filter = 'raw' )

The less good way is to simply cheat when you call the function and do an assignment + call at the same time:

$a_post = get_post($a_post_id = 439);

$a_post_id = 439 in the function arguments creates the $a_post_id variable and pass it into the function.

0

used this in the end but still not sure why get_post wouldn't work

        $secintro_args =array(
            'post__in'=>array(439),
            'posts_per_page'=>1,
            'orderby'=>'title',
            'order'=>'asc');

        $secintro = get_posts($secintro_args);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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