postgresql - How to get random posts in Wordpress heroku -
I am using WordPress heroku and am trying to display random posts in the sidebar.
I have the following code:
& lt; H2 & gt; Random Post & lt; / H2 & gt; & Lt; Ul & gt; By & lt;? $ Args = array ('posts_per_page' => 5, 'orderby' = & gt; 'rand'); $ Rand_posts = get_posts ($ Args); ? & Gt; By & lt;? $ Posts = get_posts ($ Args)? & Gt; & Lt ;? = $ Posts === Tap? "truth": "". Count ($ post)? & Gt; & Lt ;? Php foreach ($ post as $ post) {? & Gt; & Lt; Li & gt; & Lt; A href = "& lt ;? php the_ermelink () ;? & gt;" Title = "& lt ;? php the_title () ;? & gt;" & Gt; & Lt ;? Php the_title (); ? & Gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt ;? Php}? & Gt; & Lt; / Ul & gt;
This code is giving error like this:
[28-Apr-2014 23:56:59 UTC] WordPress database error error: function rand ()
I believe that WordPress Heroko does not use MySQL but uses PostgreSQL.
Does $ Heroku use PostgreSQL with random posts given on Word and not MySQL? Any smart ideas?
Thanks
You can send posts_order
filter to Change the RAND ()
section to change
:
add_filter ('posts_orderby', 'so_23353237_posts_orderby'); $ Rand_posts = get_posts ($ Args);
/ ** * Randomize Random MySQL ()) PostgreSQL * * / function so_23353237_posts_orderby ($ orderby) {remove_filter (current_filters (), __FUNCTION__); Return 'Random ()'; }
Remember to add just
'suppress_filters' = & gt; For incorrect
get_posts () logic
this has not been investigated but you get this idea; -)
Comments
Post a Comment