• I tried the code posted here:

    http://codex.wordpress.org/Function_Reference/get_post

    <?php
    $post_id_7 = get_post(7);
    $title = $post_id_7->post_title;
    ?>

    However, I keep getting this error: Fatal error: Only variables can be passed by reference in /usr/local/www/www.stockmarketgarden.com/htdocs/wp-content/themes/connections/page.php on line 36

    Any ideas as to why?

    Thanks,

    SMG

Viewing 6 replies - 1 through 6 (of 6 total)
  • Try this

    <?php
    $my_id = 7;
    $post_id_7 = get_post($my_id);
    $title = $post_id_7->post_title;
    ?>

    Thread Starter SMG

    (@smg)

    Thanks, It works.

    Does this mean that the get_post method expects a reference and not a number?

    SMG

    It expects a variable. $my_id is a variable; 7 is not.

    Thread Starter SMG

    (@smg)

    Here is the code in my page.php file inside of the connections theme folder.

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="page">
    <div class="page-info"><h2 class="page-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <?php /*Posted by <?php the_author(); ?>*/ ?><?php edit_post_link('(edit this)'); ?></div>

    <div class="page-content">

    <?php the_content();

    What I’m trying to do, is create a page that has an include in it. The include will have additional processing(i.e. PHP code). I need to detect the correct page in order to execute the include code. So, when a user opens the spcific page, the additional include will be executed thus adding additional functionality to that page and that page only. Any idea how I can do this?

    Thanks,

    SMG

    Thread Starter SMG

    (@smg)

    Thanks alphaoide,

    I also found that if I use $post->ID i can get the post ID of the current post.

    Thanks,

    SMG

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘get_post method not working’ is closed to new replies.