Random Sort Settings
This topic contains 10 replies, has 3 voices, and was last updated by Naveen Giri 4 years, 11 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
November 13, 2019 at 8:36 pm #517016
Trying to understand random sorting.
Read the snippet adjustment: https://wpgeodirectory.com/docs-v2/places/sorting/
But still not sure or not seeing impact from any changes I’ve made in testing.
Can you provide code or adjustment to that code needed to get:
– randomization every 15 minutes
– randomization every 30 minutesAnd a question, is there any negative impact to having this run at the default 24 hours vs every 30 minutes vs every 15 minutes?
Cheers
November 13, 2019 at 11:28 pm #517034You can find additional examples here:
https://wpgeodirectory.com/support/topic/listings-random-not-changing/#post-502309
November 13, 2019 at 11:57 pm #517043Excellent, that helps!
Cheers
November 14, 2019 at 12:22 am #517048Unfortunately, not sure this is working.
Trying both a ~3 minute limit as well as the “every refresh” version against the “tiered-featured” sort I was experimenting (from our other thread https://wpgeodirectory.com/support/topic/setting-up-two-levels-of-featured/#post-516997), but kept getting the same results.
To validate that something else wasn’t influencing the results with that other test, I tried refreshing multiple times against a purely “random” sort with not sub-sorting or other treatment and I continue to get the results in the same order.
Cheers
November 14, 2019 at 1:06 am #517068Please post the snippet you are using so we can take a look
November 14, 2019 at 1:54 am #517073Using the recommended Snippets plugin, I tried individually, the following code set to run everywhere.
First:
add_filter('geodir_rand_seed','_my_geodir_rand_seed'); function _my_geodir_rand_seed($rand_seed){ $rand_seed = get_transient( 'geodir_rand_seed_custom' ); // if we don't have a transient then set a new one if(!$rand_seed){ $rand_seed = time(); set_transient( 'geodir_rand_seed_custom', $rand_seed, .05 * HOUR_IN_SECONDS ); } // validate $rand_seed = absint($rand_seed); return $rand_seed; }
Then:
add_filter('geodir_rand_seed','__return_zero'); // Upon refresh
No sign of re-ordering even nearly 2 hours since I changed to the “Upon refresh” version.
Thanks
November 18, 2019 at 8:27 am #517600Hi identity,
where you checking it?
I am considering you have enabled random sorting option.
I have noticed, you have a . just before minute.
please try it and check by sorting places in random sort.
http://yoursite.com/places/?sort_by=randomadd_filter('geodir_rand_seed','_my_geodir_rand_seed'); function _my_geodir_rand_seed($rand_seed) { $rand_seed = get_transient( 'geodir_rand_seed_custom' ); // if we don't have a transient then set a new one if ( ! $rand_seed ) { $rand_seed = time(); set_transient( 'geodir_rand_seed_custom', $rand_seed, 5 * MINUTE_IN_SECONDS ); } // validate $rand_seed = absint( $rand_seed ); return $rand_seed; }
Thanks
November 18, 2019 at 5:51 pm #517680Naveen,
Thanks.
I think the coding example here:
https://wpgeodirectory.com/docs-v2/places/sorting/
may have some errors in it.I noticed some differences in your code, beyond the MINUTE_IN_SECONDS vs the HOUR_IN_SECONDS that I was using from that page.
My code, taken from https://wpgeodirectory.com/docs-v2/places/sorting/
add_filter('geodir_rand_seed','_my_geodir_rand_seed'); function _my_geodir_rand_seed($rand_seed){ $rand_seed = get_transient( 'geodir_rand_seed_custom' ); // if we don't have a transient then set a new one if(!$rand_seed){ $rand_seed = time(); set_transient( 'geodir_rand_seed_custom', $rand_seed, .05 * HOUR_IN_SECONDS ); } // validate $rand_seed = absint($rand_seed); return $rand_seed; }
VS your code:
add_filter('geodir_rand_seed','_my_geodir_rand_seed'); function _my_geodir_rand_seed($rand_seed) { $rand_seed = get_transient( 'geodir_rand_seed_custom' ); // if we don't have a transient then set a new one if ( ! $rand_seed ) { $rand_seed = time(); set_transient( 'geodir_rand_seed_custom', $rand_seed, 5 * MINUTE_IN_SECONDS ); } // validate $rand_seed = absint( $rand_seed ); return $rand_seed; }
Notice some differences between the two, especially in line 2 and line 6. Some of this may not matter, but I noticed that after adding a space in line two in my code between:
) {
That my code appears to work now also.If that is the case, it would be helpful if someone could update the code example in the GD docs.
I still haven’t been able to get the other “randomize on refresh” code to work:
add_filter('geodir_rand_seed','__return_zero'); // Upon refresh
Cheers
November 18, 2019 at 5:56 pm #517685Hi,
We will check and update the code, meanwhile instead of
add_filter(‘geodir_rand_seed’,’__return_zero’); // Upon refresh
please try
add_filter(‘geodir_rand_seed’,’__return_false’); // Upon refresh
Thanks
November 18, 2019 at 8:33 pm #517696No, that doesn’t seem to work either.
That would be nice for testing, but at least this other code works now and the timing can be adjusted to a smaller delay for testing.
Just to confirm and as I further edited the code for coding consistency and have tested and it appears to be working, this is the code that I am using now for randomization every 5 minutes.
add_filter('geodir_rand_seed','_my_geodir_rand_seed'); function _my_geodir_rand_seed($rand_seed) { $rand_seed = get_transient('geodir_rand_seed_custom'); // if we don't have a transient then set a new one if (!$rand_seed) { $rand_seed = time(); set_transient('geodir_rand_seed_custom', $rand_seed, 5 * MINUTE_IN_SECONDS); } // validate $rand_seed = absint($rand_seed); return $rand_seed; }
Which I have set to run in the Snippets plugin, set to Run Snippet Everywhere, though I imagine this could be set to just run on the Front-end.
Cheers
November 19, 2019 at 7:48 am #517745thanks for confirming
Yes, the code will run only for archive page queries. -
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket