Missing listings when sorted by random

This topic contains 7 replies, has 3 voices, and was last updated by  Stiofan O’Connor 8 years, 3 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #336007

    BL Interactive
    Expired Member
    Post count: 83

    I may seem like a broken record with the Random sorting issues, but the Client has lost their patience.

    Now one of their paying members is not showing up on random sort (required to be default). I can attest that through multiple paginations, refreshes, and safe browsing. The listing only showed up a single time.

    Examples in a private message:

    Please advise. I do not want to find a replacement for GeoDirectory. I love everything else that it does.

    #336008

    BL Interactive
    Expired Member
    Post count: 83
    This reply has been marked as private.
    #336117

    Guust
    Moderator
    Post count: 29970
    This reply has been marked as private.
    #336200

    BL Interactive
    Expired Member
    Post count: 83

    Multiple people have not been able to find it, on various computers. switching to A_Z and back, or being logged in helps. But this is a directory plug-in and if paying members are not showing up, that is a huge issue.

    As for random not being default, it is. When you change the sort, the URL is appended with ?sort_by=post_title_asc so simply refreshing the page keeps the sort order.

    #336218

    Guust
    Moderator
    Post count: 29970
    This reply has been marked as private.
    #336413

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Random sort and caching are not friends, it seems you are on wp-engine, i doubt that would ever work.

    Stiofan

    #348314

    BL Interactive
    Expired Member
    Post count: 83

    Shit. After much fuss, my client has formally requested a Geodirectery replacement if I cannot resolve this issue in 1 week. I am willing to pay to get this sorted out (no pun intended).

    Caching aside, I can disable that.

    Can anyone shine some light on integrating this snippet?

    
    
    <?php
    session_start();
    add_filter( 'posts_orderby', 'randomise_with_pagination' );
    function randomise_with_pagination( $orderby ) {
    	if( is_front_page() ) {
    	  	// Reset seed on load of initial archive page
    		if( ! get_query_var( 'paged' ) || get_query_var( 'paged' ) == 0 || get_query_var( 'paged' ) == 1 ) {
    			if( isset( $_SESSION['seed'] ) ) {
    				unset( $_SESSION['seed'] );
    			}
    		}
    	
    		// Get seed from session variable if it exists
    		$seed = false;
    		if( isset( $_SESSION['seed'] ) ) {
    			$seed = $_SESSION['seed'];
    		}
    	
    	    	// Set new seed if none exists
    	    	if ( ! $seed ) {
    	      		$seed = rand();
    	      		$_SESSION['seed'] = $seed;
    	    	}
    	
    	    	// Update ORDER BY clause to use seed
    	    	$orderby = 'RAND(' . $seed . ')';
    	}
    	return $orderby;
    }
    ?>

    I’m not sure how to call GD posts to replace if( is_front_page() ) {

    Any help will be much appreciated.

    Though, the author of this script mentioned:

    Anyway – I thought I’d jump in here quickly to let you know that as of WordPress 4.5, that snippet in my post will be unnecessary (although it will still work of course). The reason for this is that in v4.5+ you will be able to specify a seed value for the random ordering from directly within the WP_Query args. So you can set your orderby parameter to look like this: rand(123) (where ‘123’ is your seed value) – that will achieve the same results as the solution in my post, but using much less code. You’ll still need to use the session to store the seed value, but you won’t need to use the posts_orderby filter anymore. Pretty neat!

    #348481

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Are you still on wp-engine hosting? I don’t believe they even support sessions so again that code snippet would never work on their hosting.

    Stiofan

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

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

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount