Hey, I'm looking for a good way to take the grid view of a directory form entry and get it to show random entries from the form. I think I can do it with this code snippet example, but... I don't know how to tell it to give me a random ordering. I get the ascending and descending part, but how do I tell it to sort randomly? I'm also wanting this to resort when the page reloads, if that saves a question. I was assuming the random in itself would shuffle automatically on a page load.
add_filter('frm_view_order', 'change_view_order', 10, 2); function change_view_order($query, $args){ if ( $args['display']->ID == 2412 ) { //replace 2412 with you Field ID $query['order'] = 'ORDER BY MONTH(it.created_at) ASC'; } return $query; }
Hi Scott,
If you just want to randomise the entries shown in a view you can do that without custom code.
In the 'Sort Entries' section, at the bottom of the list is an option for 'Random' which will randomise the order the entries are shown. You can combine this with the 'Limit' setings to only show a set number of random entries if you wish.
Hope that helps
Chris
Example here: https://development.fdmdigital.co.uk/demo-view-page/
That's exactly what I was looking for. I'm a bit surprised their support didn't start there instead of web hooks...
Thanks. I never would have looked under the left drop down... kept trying to figure out why it wasn't an option on the right side drop down.
Whenever you're customizing a MySQL query, it's best to test your ideas in PHPMyAdmin first. Once you write a query that works the way you want, then you could transfer the working code to Formidable. There are multiple ways to generate SQL select statements where the results are in a random order. Here are a few of them that use the SQL RAND() function: https://www.mysqltutorial.org/select-random-records-database-table.aspx
Please login or Register to submit your answer