How to display random post
-
Hello π
I know that exist similar topic but my question is little diffrent.
So, I must draw post title, post content and post author from my database in random way.
My job: Create 2 script.
first: display post content ( in random way and order by ID) this isn’t work perfect:
I have :$wynik = $conn->query("select id, post_title, post_author, post_date_gmt, post_content from wp_posts where post_status='publish' and post_type='movies' order by id DESC LIMIT 1 "); while ($wiersz = $wynik ->fetch_array()){ echo $wiersz['ID'] ."</br>"; echo $wiersz['post_title'] ."</br>"; echo $wiersz['post_author']."</br>"; echo $wiersz['post_date_gmt'] ."</br>"; echo $wiersz['post_content'] ."</br>"; }
second: display post title ( 12 newest posts) and this work perfect!
$wynik = $conn->query("select * from wp_posts where post_status='publish' and post_type='movies' order by post_modified_gmt DESC LIMIT 12 "); while ($wiersz = $wynik ->fetch_array()){ echo "<a href=".$wiersz['ID'].">". $wiersz['post_title'] ."</a>\n<br/>"; echo "<hr>"; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to display random post’ is closed to new replies.