[wp-trac] [WordPress Trac] #36980: get_the_ID () if used outside of a loop returns first post ID

WordPress Trac noreply at wordpress.org
Wed Jun 1 12:50:22 UTC 2016


#36980: get_the_ID () if used outside of a loop returns first post ID
-------------------------------+------------------------------
 Reporter:  Themezly           |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  4.5.2
 Severity:  normal             |  Resolution:
 Keywords:                     |     Focuses:
-------------------------------+------------------------------

Comment (by Themezly):

 OK understandable but should't  static page id be targeted with
 get_queried_object_id() than?

 I am doing this hack becuase of this "bug/feature"


 {{{
 function _thz_post_id() {
   if (in_the_loop()) {
        $post_id = get_the_ID();
   } else {
        $post_id =get_queried_object_id() == 0 ? 999999999999
 :get_queried_object_id() ;
          }
   return $post_id;
 }
 }}}

 but in my opinion if get_the_ID() is caught outside of the loop it should
 not return anything or it should return the get_queried_object_id()
 instead of picking any items from the loop.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36980#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list