{"id":305,"date":"2015-09-22T12:53:16","date_gmt":"2015-09-22T12:53:16","guid":{"rendered":"http:\/\/www.eminozlem.com\/?p=305"},"modified":"2015-09-22T12:55:51","modified_gmt":"2015-09-22T12:55:51","slug":"fastest-way-to-get-a-random-post-link-in-wp","status":"publish","type":"post","link":"https:\/\/eminozlem.com\/tr\/fastest-way-to-get-a-random-post-link-in-wp\/","title":{"rendered":"Fastest way to get a random post link in wp"},"content":{"rendered":"<p>Previously we have established that the <a title=\"Fastest way to get 1 post-&gt;ID in WordPress\" href=\"http:\/\/www.eminozlem.com\/web\/fastest-way-to-get-1-post-id-in-wordpress\/\">fastest way to get an ID is using wpdb<\/a> . So, simply to get a random post link use:<\/p>\n<pre class=\"lang:php decode:true  \">\tfunction eo_get_a_rand_postlink() {\r\n\t\tglobal $wpdb;\r\n\t\t$rand_post_id = $wpdb-&gt;get_var(\"SELECT ID FROM $wpdb-&gt;posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY RAND() LIMIT 1\");\r\n\t\treturn get_permalink($rand_post_id);\r\n\t}<\/pre>\n<p><a href=\"http:\/\/static.eminozlem.com\/uploads\/2015\/09\/g1rlClipboard01.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"951\" height=\"257\" class=\"alignnone size-full wp-image-307\" src=\"http:\/\/static.eminozlem.com\/uploads\/2015\/09\/g1rlClipboard01.jpg\" alt=\"g1rlClipboard01\" srcset=\"https:\/\/static.eminozlem.com\/uploads\/2015\/09\/g1rlClipboard01.jpg 951w, https:\/\/static.eminozlem.com\/uploads\/2015\/09\/g1rlClipboard01-720x195.jpg 720w\" sizes=\"auto, (max-width: 951px) 100vw, 951px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previously we have established that the fastest way to get an ID is using wpdb . So, simply to get a random post link use: function eo_get_a_rand_postlink() { global $wpdb; $rand_post_id = $wpdb-&gt;get_var(&#8220;SELECT ID FROM $wpdb-&gt;posts WHERE post_status = &#8216;publish&#8217; AND post_type = &#8216;post&#8217; ORDER BY RAND() LIMIT 1&#8221;); return get_permalink($rand_post_id); }<\/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":[1],"tags":[],"class_list":["post-305","post","type-post","status-publish","format-standard","hentry","category-web"],"acf":[],"_links":{"self":[{"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/posts\/305","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=305"}],"version-history":[{"count":0,"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/posts\/305\/revisions"}],"wp:attachment":[{"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/media?parent=305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/categories?post=305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eminozlem.com\/tr\/wp-json\/wp\/v2\/tags?post=305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}