• Hi,

    I’m using the following code inside functions.php to get the ID of the current product/post. But for some reason it returns nothing.

    global $wp_query;
    $post_id = $wp_query->post->ID;

    Any idea?
    Thanks

Viewing 1 replies (of 1 total)
  • why are you using a global $wp_query?
    if it was set somewhere and this code is being called, what was it set to?

    Try adding a
    echo 'wp_query='.var_dump($wp_query).'<br>';
    to make sure $wp_query contains something.

Viewing 1 replies (of 1 total)
  • The topic ‘Unable to get current product/post ID inside functions.php’ is closed to new replies.