WordPress.org

Ready to get started?Download WordPress

Forums

get_post method not working (7 posts)

  1. SMG
    Member
    Posted 8 years ago #

    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

  2. Joshua Sigar
    Member
    Posted 8 years ago #

    Try this

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

  3. SMG
    Member
    Posted 8 years ago #

    Thanks, It works.

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

    SMG

  4. Joshua Sigar
    Member
    Posted 8 years ago #

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

  5. SMG
    Member
    Posted 8 years ago #

    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

  6. Joshua Sigar
    Member
    Posted 8 years ago #

  7. SMG
    Member
    Posted 8 years ago #

    Thanks alphaoide,

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

    Thanks,

    SMG

Topic Closed

This topic has been closed to new replies.

About this Topic