Title: get_post method not working
Last modified: August 18, 2016

---

# get_post method not working

 *  [SMG](https://wordpress.org/support/users/smg/)
 * (@smg)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/get_post-method-not-working/)
 * I tried the code posted here:
 * [http://codex.wordpress.org/Function_Reference/get_post](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)

 *  [Joshua Sigar](https://wordpress.org/support/users/alphaoide/)
 * (@alphaoide)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/get_post-method-not-working/#post-309177)
 * Try this
 * `<?php
    $my_id = 7; $post_id_7 = get_post($my_id); $title = $post_id_7->post_title;?
   >
 *  Thread Starter [SMG](https://wordpress.org/support/users/smg/)
 * (@smg)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/get_post-method-not-working/#post-309180)
 * Thanks, It works.
 * Does this mean that the get_post method expects a reference and not a number?
 * SMG
 *  [Joshua Sigar](https://wordpress.org/support/users/alphaoide/)
 * (@alphaoide)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/get_post-method-not-working/#post-309182)
 * It expects a variable. `$my_id` is a variable; `7` is not.
 *  Thread Starter [SMG](https://wordpress.org/support/users/smg/)
 * (@smg)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/get_post-method-not-working/#post-309218)
 * 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
 *  [Joshua Sigar](https://wordpress.org/support/users/alphaoide/)
 * (@alphaoide)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/get_post-method-not-working/#post-309257)
 * [http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page](http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page)
 *  Thread Starter [SMG](https://wordpress.org/support/users/smg/)
 * (@smg)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/get_post-method-not-working/#post-309258)
 * 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.

## Tags

 * [get_post](https://wordpress.org/support/topic-tag/get_post/)
 * [post_title](https://wordpress.org/support/topic-tag/post_title/)

 * 6 replies
 * 2 participants
 * Last reply from: [SMG](https://wordpress.org/support/users/smg/)
 * Last activity: [20 years, 5 months ago](https://wordpress.org/support/topic/get_post-method-not-working/#post-309258)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
