Really Short Randomization Time

This topic contains 4 replies, has 3 voices, and was last updated by  Naveen Giri 4 years, 5 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #517017

    Will Hill
    Expired Member
    Post count: 73

    Is it possible to set a really short randomization time, or would that overload the website? I’ve tried using the code from the documentation, but editing the number to be minutes instead of hours:

    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, 1 * MINUTE_IN_SECONDS );
    }

    // validate
    $rand_seed = absint($rand_seed);

    return $rand_seed;
    }

    The goal is to be able to have a sidebar widget that shows a listing, but I’d like it to show a different listing pretty much every time the user loads a new page. Is that possible?

    Thanks!

    #517027

    Will Hill
    Expired Member
    Post count: 73

    I tried using the code found here as well: https://wpgeodirectory.com/support/topic/listings-random-not-changing/#post-502309

    But it didn’t seem to have any effect.

    #517038

    Alex Rollin
    Moderator
    Post count: 27815

    Add the snippet here first, and set the time as you like, to maybe 1 for 1 second

    https://wpgeodirectory.com/support/topic/random-display-of-listings/#post-467205

    #517041

    Will Hill
    Expired Member
    Post count: 73

    So would that just look like this:
    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, 1 );
    }

    // validate
    $rand_seed = absint($rand_seed);

    return $rand_seed;
    }

    I just want to make sure I have the code right, since my PHP ins’t great.

    #517601

    Naveen Giri
    Moderator
    Post count: 1559

    Hi Will,

    sorry for late reply. you can try below code instead to get random listing on each page refresh.

    add_filter(‘geodir_rand_seed’,’__return_false’); // Upon refresh

    Thanks

Viewing 5 posts - 1 through 5 (of 5 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket