• Resolved 7 Mysteries

    (@1greatness)


    How can I make a query loop to display posts by random order? There is no option to order by random on the query loop block options; only “Newest to oldest, Oldest to newest, A to Z, Z to A” options available.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Moderator Kathryn Presner

    (@zoonini)

    Hi @1greatness – there isn’t currently an option to have the Query Loop display posts in a randomized fashion, but there is an enhancement request to track this:

    https://github.com/WordPress/gutenberg/issues/40481

    You could always try a plugin that offers a shortcode option, and then add that to a Shortcode block.

    Thread Starter 7 Mysteries

    (@1greatness)

    I think I have solved the problem myself. On the editor screen, I switched to code editor and located the query loop block I was trying to order by random. Then I changed "orderBy":"date" to "orderBy":"rand" .

    If you know a better way to do it, please tell me.

    Moderator Kathryn Presner

    (@zoonini)

    @1greatness – editing the Query Loop code directly in the block editor isn’t an ideal solution, as those parameters are not meant to be changed manually. When I just tested it now, I was unable to return to the Visual Editor and view the block; there’s just a spinning icon.

    If you know a better way to do it, please tell me.

    I would try the shortcode/plugin method I mentioned above.

    Thread Starter 7 Mysteries

    (@1greatness)

    Hi @zoonini – thank you for your urgent response, I appreciate.

    I’m trying to do something similar except I want to sort by a ‘custom field’, created with plugin PODs

    my code is..

    <!-- wp:query {"queryId":7,"query":{"perPage":"9","pages":0,"offset":0,"postType":"post","order":"asc","orderBy":"date",....

    I’d like to change “date” to “event_date” but it just hangs?

    Moderator Kathryn Presner

    (@zoonini)

    Hi @rjbrugman – could you please go ahead and start a new thread with your question, as it’s much easier to help people with customization requests one-on-one. Thanks!

    Thread Starter 7 Mysteries

    (@1greatness)

    Hello @rjbrugman – maybe it’s because "event_date" is not among the list of "orderBy" reference in the WordPress documentation. If "orderBy":"event_date" is valid, then you should install Spectra plugin and try the code again, it may work. I realised that the Spectra plugin is responsible for the "orderBy":"rand" code to function on my website.

    If your custom field has its own category, you should filter it with the name of the category.

    Moderator Kathryn Presner

    (@zoonini)

    @1greatness Thanks for chiming in, please feel free to add your insights to the new thread here!

    The Github discussion is going nowhere. Random posts is a feature that was available before Gutenberg and it should be available now.

    Installing a plugin for every feature that has been gimped in Gutenberg is insane.

    Moderator Felipe Santos

    (@foosantos)

    Hi @knocks, I understand the frustration, but not much can be done here, please use the GitHub issue for more details.

    There are a lot of possibilities for Gutenberg, so it is always challenging to prioritize. If you are a developer, you could create a pull request from there.

    PS: I would generally recommend you open a new thread anyway if you need additional help, but keeping track on GitHub is ideal if you have the same feature request.

    supaiku

    (@supaiku)

    I was able to implement the manual workaround suggesed by @1greatness of switching to the code editor and swapping "orderBy":"date" with "orderBy":"rand" .

    I could still edit the rest of the blocks, but the query loop didn’t load in Gutenburg anymore for editing, which is fine. I saved it as a pattern first, so I can re-create if it needed, and re-do the hack. Pagination seems to work just fine too: https://www.sociocracyforall.org/content/#Sociocracy_articles_and_videos

    It seems clear that the functionality is hung up with Gutenburg’s development team here despite being supported by wordpress.
    https://github.com/WordPress/gutenberg/pull/50999

    There’s question about the usefulness of randomized sorting (which is frankly puzzling), and concern about performance and caching impacts. These issues don’t seem worth not having the functionality to me, but so it goes…

    Since it seems Gutenburg developers are uninterested in enabling this function, it would be handy if there were a plugin that just enabled the GUI selectability for random sorting in Gutenburg and did nothing else, because I don’t want to add extra bulky plugins, but given that this work-around isn’t too inconvenient, I’m content to hack Gutenburg in this way, as ugly as it is.

    • This reply was modified 11 months ago by supaiku.
    • This reply was modified 11 months ago by supaiku.
    • This reply was modified 11 months ago by supaiku.
    Thread Starter 7 Mysteries

    (@1greatness)

    Hi @supaiku, If you install and activate “Spectra – WordPress Gutenberg Blocks” plugin by Brainstorm Force, the query loop block may still work as normal: no errors.

    supaiku

    (@supaiku)

    Thanks, this particular site has a too many plugins issues, so I’ll probably just deal with the work around, but that’s sort handy and I might try it out on another!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How can I make a query loop to display posts by random order?’ is closed to new replies.