Title: Function get_the_ID() changes behaviour on child theme
Last modified: January 9, 2017

---

# Function get_the_ID() changes behaviour on child theme

 *  [setnara2000](https://wordpress.org/support/users/setnara2000/)
 * (@setnara2000)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/function-get_the_id-changes-behaviour-on-child-theme/)
 * This is a very strange issue… One that is even hard to explain.
 * Imagine a parent theme (in principle, everything work as expected)
 * Than I add a child theme with only style.css.
 * In the parent theme I use the function “get_the_ID()”. It doesn’t matter where.
 * The fact is that if I activate the Parent Theme (completely disregarding the 
   child theme) it correctly tells me the ID of the page I’m visiting (this is true
   to all pages of the site).
 * Now, if I activate the child theme (remember that it only has a CSS), the same
   function gives me a single ID all the time.
 * I read in various forums that this would be a problem associated with custom 
   queries (WP_Query) that were missing wp_reset_postdata() afterwards.
 * I don’t think this is the case here, as the child theme is not introducing any
   PHP. Have you ever see anything like this?
 * Thanks,
    Andres Now
 * But if I activate
    -  This topic was modified 9 years, 5 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/function-get_the_id-changes-behaviour-on-child-theme/#post-8636739)
 * get_the_ID() requires the global $post object to contain a post object. Outside
   of the loop, this is not guaranteed. In some cases it’ll work, in others it will
   not. It’s unpredictable. If you’re using it outside of the loop you are using
   it wrong. If you are inside the loop and it’s not returning the current post 
   ID, then there is a flaw or conflict in code somewhere.

Viewing 1 replies (of 1 total)

The topic ‘Function get_the_ID() changes behaviour on child theme’ is closed to 
new replies.

## Tags

 * [child theme](https://wordpress.org/support/topic-tag/child-theme/)
 * [get_the_id](https://wordpress.org/support/topic-tag/get_the_id/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/function-get_the_id-changes-behaviour-on-child-theme/#post-8636739)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
