Skip to main content
added 482 characters in body
Source Link
jgraup
  • 9.8k
  • 3
  • 32
  • 68

When $post is null for get_post it looks to $GLOBALS['post'].

There are several other checks in the source so perhaps you should find out the value of the global variable when you're calling it or give it something besides and empty value.

What does get_the_id() return vs. get_post(get_queried_object_id())? Or var_dump(get_queried_object())?

get_post() - Retrieves post data given a post ID or post object.

get_queried_object() - Retrieve the currently-queried object. For example:

  • if you're on a single post, it will return the post object
  • if you're on a page, it will return the page object
  • if you're on an archive page, it will return the post type object
  • if you're on a category archive, it will return the category object
  • if you're on an author archive, it will return the author object etc.

When $post is null for get_post it looks to $GLOBALS['post'].

There are several other checks in the source so perhaps you should find out the value of the global variable when you're calling it or give it something besides and empty value.

What does get_the_id() return vs. get_post(get_queried_object_id())? Or var_dump(get_queried_object())?

When $post is null for get_post it looks to $GLOBALS['post'].

There are several other checks in the source so perhaps you should find out the value of the global variable when you're calling it or give it something besides and empty value.

What does get_the_id() return vs. get_post(get_queried_object_id())? Or var_dump(get_queried_object())?

get_post() - Retrieves post data given a post ID or post object.

get_queried_object() - Retrieve the currently-queried object. For example:

  • if you're on a single post, it will return the post object
  • if you're on a page, it will return the page object
  • if you're on an archive page, it will return the post type object
  • if you're on a category archive, it will return the category object
  • if you're on an author archive, it will return the author object etc.
Source Link
jgraup
  • 9.8k
  • 3
  • 32
  • 68

When $post is null for get_post it looks to $GLOBALS['post'].

There are several other checks in the source so perhaps you should find out the value of the global variable when you're calling it or give it something besides and empty value.

What does get_the_id() return vs. get_post(get_queried_object_id())? Or var_dump(get_queried_object())?