{"id":180,"date":"2015-04-17T14:50:16","date_gmt":"2015-04-17T14:50:16","guid":{"rendered":"http:\/\/www.eminozlem.com\/?p=180"},"modified":"2015-06-06T21:29:58","modified_gmt":"2015-06-06T21:29:58","slug":"fastest-way-to-get-user-id-in-wordpress","status":"publish","type":"post","link":"https:\/\/eminozlem.com\/tr\/fastest-way-to-get-user-id-in-wordpress\/","title":{"rendered":"Fastest way to get user ID in wordpress"},"content":{"rendered":"<p>There are various ways to get user_ID in WP. But which one is the fastest ? I&#8217;ve compared 3 ways<\/p>\n<pre class=\"lang:php decode:true\">\tfunction get_uid_from_global() {\r\n\t\tglobal $current_user;\r\n\t\treturn $current_user-&gt;ID;\r\n\t}\r\n\t\r\n\tfunction get_uid_by_gcuid() {\r\n\t\treturn get_current_user_id();\t\r\n\t}\r\n\tfunction get_uid_by_wpgcu_id() {\r\n\t\treturn wp_get_current_user()-&gt;ID;\t\r\n\t}<\/pre>\n<p>Without a doubt, global method was fastest. With multiple 100,000 runs, global method took 0.9~ sec, while wp_get_current_user()-&gt;ID method took took 1.3~ sec and get_current_user_id() took 1.5~ sec.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are various ways to get user_ID in WP. But which one is the fastest ? I&#8217;ve compared 3 ways function get_uid_from_global() { global $current_user; return $current_user-&gt;ID; } function get_uid_by_gcuid() { return get_current_user_id(); } function get_uid_by_wpgcu_id() { return wp_get_current_user()-&gt;ID; } Without a doubt, global method was fastest. With multiple 100,000 runs, global method took 0.9~&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[7,50,2],"tags":[54,53,52,51,68],"class_list":["post-180","post","type-post","status-publish","format-standard","hentry","category-coding","category-snippets","category-wordpress","tag-benchmark","tag-performance","tag-uid","tag-user-id","tag-wordpress"],"acf":[],"_links":{"self":[{"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/posts\/180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/comments?post=180"}],"version-history":[{"count":0,"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/posts\/180\/revisions"}],"wp:attachment":[{"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/media?parent=180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/categories?post=180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/tags?post=180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}