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

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

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -