Skip Navigation

[Resolved] Load random posts on page refresh

This thread is resolved. Here is a description of the problem and solution.

Problem:

Create a button so that when clicked, it refreshes a Toolset View I created that shows 2 random posts, it just loads the same 2 posts that were previously shown before the page was reloaded.

Solution:

There might be other compatibility problem of your website, Please try these:

1) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2019, and test again

2) If the problem is fixed, you can activate other plugins/theme one by one, try to locate the problem plugin/theme

Relevant Documentation:

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by patrickM-18 5 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1360097
Show_Me_Something_Fun_Page.png

I am trying to: Create a button so that when clicked, it refreshes a Toolset View I created that shows 2 random posts.

Link to a page where the issue can be seen: hidden link

I expected to see: Since I set View to Order by Random and only display 2 posts, that it would return to NEW random posts on a page reload.

Instead, I got: it just loads the same 2 posts that were previously shown before the page was reloaded. (I've tried putting a "submit" and a "reset" button, each did not work for me either.

#1360209

Hello,

Thanks for details, I can see the problem in your website.
Here are what I found:
Q1) When I click the "Roll The Dice" button, I see some JS error in my browser console window, for example:
Uncaught TypeError: Cannot read property 'querySelectorAll' of undefined
I suggest you try to fix those JS errors first.

Q2) And the problem you mentioned above persists when I refresh the browser by pressing F5 key.
Please check these:
1) Follow our document to display the Views shortcode:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-view

For example:
[wpv-view name="My amazing custom post list"]
Without "order" or "orderby" attributes

2) It might be a cache problem, please deactivate all other plugins, and switch to wordpress default theme 2019, and test again

#1360587

Hi Luo, I created another page where we can troubleshoot this: hidden link

I tried the adding the shortcode, both with and without cached="off". When I refresh the page, the same 2 posts that were shown previously are being shown. I'm hoping that the view will reload 2 new random posts on every page refresh.

In terms of the "Uncaught TypeError: Cannot read property 'querySelectorAll' of undefined", I believe those to be unrelated because that error appears when you click anywhere on our screen. Disabling plugins and changing the theme is not really an option for us.

How else might we get this functionality to work? Is it expected that if ordering by "random", that every time the page refreshes, new random posts will be displayed?

#1361019

Thanks for the confirmation, I have tried the same setting in my localhost with a fresh wordpress installation, it works fine, when I refresh the page, it display other random posts.

So the problem is abnormal, there might be other compatibility problem of your website, as I mentioned above:
Please try these:
1) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2019, and test again
2) If the problem is fixed, you can activate other plugins/theme one by one, try to locate the problem plugin/theme

If you need assistance to locate the problem, please provide a copy of your website(you can put the duplicator package in your own google drive disk, and share the link in below private message box).

#1362311

Thanks for the details, I am downloading the files, will update here if there is anything found.

#1362317

The files you provided above is not valid to duplicate the problem, I got a lots of MySQL errors when import those SQL files.

Have you tried as I mentioned above to locate the problem plugin/theme:
https://toolset.com/forums/topic/load-random-posts-on-page-refresh/#post-1361019
deactivate all other plugins, and switch to wordpress default theme 2019, and test again

You can also provide a test site with the same problem, provide website credentials and FTP access in below private message box, I need to deactivate plugins/theme in it, thanks

#1363007

Figured it out by replicating the pagination button as a "refresh" button. Accomplishes the same goal to the user. The plugins that were interfering were necessary for the rest of the site to function, so I wasn't able to do that as a solution.