php - Selection of a random AND 'published' row from table in mysql -


i've read many answers question none seem answer in scenario when need pick 1 random row in db of articles, wordpress db, in wp_posts, have both revisions, trashed , published articles.

previous answers seems return blank result if id random , post not published in code

select * wp_posts w     join (select (rand() *  (select max(id)  wp_posts)) id)  r2     w.id >= r2.id     , w.post_status = 'publish'     order w.id asc     limit 1 

just use

select *  wp_posts post_status = 'publish' order rand() limit 1 

to random record being published.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

android - How to create dynamically Fragment pager adapter -