• Resolved afaust

    (@afaust)


    Is there a way to have different pools? I want to have two different related post widgets on one page. One would show relate content and the other would show related staff. I do not want these to be in the same pool. I hope that makes sense.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Michael Nelson

    (@mnelson4)

    Yes @afaust that’s possible with some custom PHP. I’m going to show it to you, but if typing out PHP is too daunting for you I’d recommend you talk to (or hire) a developer.

    But this is the PHP you could use:

    
    <h2>Related</h2>
    <?php yarpp_related(); ?>
    <h2>Staff</h2>
    <?php yarpp_related(array('post_type' => 'staff'));?>
    

    The first call to yarpp_related() uses all of YARPP’s settings set in the admin and so can use YARPP’s cached results (so it’s very efficient).
    The second call to yarpp_related() forces YARPP to only return posts of type “staff” (I’m guessing that’s your custom post’s type, otherwise you should replace that with whatever it is for your staff post type). Unfortunately YARPP isn’t currently setup to cache this second query, so it’s not terribly efficient (the query can take half a second on large sites). If you want to improve efficiency you’d have to use WordPress’ set_transient function to cache the results yourself. Something like this:

    
    <h1>Custom query</h1>
    <?php
    $result = get_transient('yarpp_custom_results_for_' . $post->ID);
    if(! $result){
    	$result = yarpp_related(['post_type' => 'staff'],null,false);
    	set_transient('yarpp_custom_results_for_' . $post->ID, $result,60 * MINUTE_IN_SECONDS);
    }
    echo $result;
    

    That will cache the YARPP results for 60 minutes.

    Does that make sense?

    Plugin Support Michael Nelson

    (@mnelson4)

    Oh and here’s our FAQ which has more info about writing YARPP custom queries: https://www.ads-software.com/plugins/yet-another-related-posts-plugin/#can%20i%20customize%20how%20yarpp%20displays%3F

    Thread Starter afaust

    (@afaust)

    Thanks will take a look

    Plugin Support Michael Nelson

    (@mnelson4)

    oh I just realized one unexpected requirement to get the above to work: you need to set “Display results from all post types” to CHECKED (see screenshot).

    Plugin Author YARPP

    (@jeffparker)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Different Pools’ is closed to new replies.