Title: BUG: Undefined $post_id
Last modified: August 21, 2016

---

# BUG: Undefined $post_id

 *  Resolved [Patrick Daly](https://wordpress.org/support/users/developdaly/)
 * (@developdaly)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/bug-undefined-post_id/)
 * I’m accessing the function `add_subscription` directly from within in my theme
   and it kept failing. I tracked it down to a typo in the function.
 * Lines 611-616:
 *     ```
       public function add_subscription($_post_id = 0, $_email = '', $_status = 'Y'){
       		global $wpdb;
   
       		// Does the post exist?
       		$target_post = get_post($post_id);
       		if (($post_id > 0) && !is_object($target_post))
       ```
   
 * … the last two lines should be using `$_post_id` instead of `$post_id`.
 * [http://wordpress.org/plugins/subscribe-to-comments-reloaded/](http://wordpress.org/plugins/subscribe-to-comments-reloaded/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Israel Barragan](https://wordpress.org/support/users/reedyseth/)
 * (@reedyseth)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/bug-undefined-post_id/#post-4493243)
 * Hello [@patrick](https://wordpress.org/support/users/patrick/) Daly I checked
   it out and the post id is save correcty on the database, but if you use the function
   outside of the plugin you may encounter this kind of behavior.
 * Can you tell me how are you using it so that I can help you to solve this out
   or if I find how this is affecting the plugin then fix it.
 * Regards !!
 *  Thread Starter [Patrick Daly](https://wordpress.org/support/users/developdaly/)
 * (@developdaly)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/bug-undefined-post_id/#post-4493271)
 * The function will work in most cases because the actual insertion query a few
   lines later is correct, `$wpdb->query($wpdb->prepare("`. But the part of the 
   function checking if the post exists doesn’t work and results in a PHP NOTICE.
   Most users wouldn’t see this … even with verbose error reporting turned on. I’m
   adding/deleting subscriptions on the front-end of my site with ajax though, and
   the NOTICE is returned in the response and breaks my output.
 *  [Israel Barragan](https://wordpress.org/support/users/reedyseth/)
 * (@reedyseth)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/bug-undefined-post_id/#post-4493272)
 * Alright, so let me change to $_post_ID and debug the application to make sure
   everything works alright.
 *  [Raam Dev](https://wordpress.org/support/users/raamdev/)
 * (@raamdev)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/bug-undefined-post_id/#post-4493408)
 * [@patrick](https://wordpress.org/support/users/patrick/) Daly Thank you for reporting
   this. This has been fixed in the development trunk (see [https://github.com/stcr/subscribe-to-comments-reloaded/commit/5d20eaf7ef91c83db1798bd83991770346141215](https://github.com/stcr/subscribe-to-comments-reloaded/commit/5d20eaf7ef91c83db1798bd83991770346141215))
   and this will go out with the next release.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘BUG: Undefined $post_id’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/subscribe-to-comments-reloaded_f0f9fc.
   svg)
 * [Subscribe To Comments Reloaded](https://wordpress.org/plugins/subscribe-to-comments-reloaded/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/subscribe-to-comments-reloaded/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/subscribe-to-comments-reloaded/)
 * [Active Topics](https://wordpress.org/support/plugin/subscribe-to-comments-reloaded/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/subscribe-to-comments-reloaded/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/subscribe-to-comments-reloaded/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [Raam Dev](https://wordpress.org/support/users/raamdev/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/bug-undefined-post_id/#post-4493408)
 * Status: resolved