• 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 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Michael Nelson


    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:

    <?php yarpp_related(); ?>
    <?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>
    $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 Author Michael Nelson


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

    Thread Starter afaust


    Thanks will take a look

    Plugin Author Michael Nelson


    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).

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.