Testimonies

Support Area Forums Elite Testimonies

Viewing 3 posts - 1 through 3 (of 3 total)
URL to the page in question:
  • Author
    Posts
  • #16922
    Mark Newton
    Participant

    Bill,

    Are the testimonies rotated for display or how do I get more than one testimony to enter into rotation for display? I am using the widget of course.

    I have five testimonies under “Testimonies”, all published. I have not selected an order under attributes nor a parent.

    Thanks!
    Mark
    [marksnewton.com]

    #16924
    Bill Robbins
    Moderator

    Hello Mark,

    For the testimonies widget, there is a small query that pulls those. If you’re curious here’s a copy of it:

    
    if ( ! ( $query = get_transient( 'testimony_posts' ) ) ) {
    			
    $args = array( 
    	'post_type' => 'testimony', 
    	'orderby' => 'rand', 
    	'order' => 'asc',
    	'posts_per_page' => '1', 
    	'no_found_rows' => true
    );
    				
    set_transient( 'testimony_posts', $query, 600 );
    			
    }
    				  
    $testimony = new WP_Query( $args );
    

    The first check’s to see if this query already has a transient set. We cache the results of this query for 600 seconds.

    After that, the query is run. It will randomly select one testimony at a time and display it.

    Since you’re hosting with WP Engine, you’ll want to set your site to allow orderby rand in the WP Engine section of your control panel. They disable that by default, but since we’re using a transient to cache the results, it’ll work nicely with their system.

    Once that’s set you should have more than one appear as long as more than one is published.

    Hope that helps out,
    Bill

    #16926
    Mark Newton
    Participant

    Bam! Nailed it like a champ. Yes, orderby rand was OFF. Clean code sir. Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Testimonies’ is closed to new replies.