• frafor

    (@frafor)


    Hi there,

    On a magazine I’m developing I’ve decided to use YARPP and it seems to be a great plugin.

    Since some pages consists in many loops and related posts are rendered via PHP at different levels of correlation, I managed to exclude already displayed posts in subsequent loops by using a global variable, hooked in the_post, like:

    global $shown_posts;
    
    function post_is_shown($post) { global $shown_posts; $shown_posts[] = $post->ID; }
    
    add_action('the_post', 'post_is_shown', 100);

    Then I’m excluding the collected post ids on subsequent Wp_Query-ies by using pre_get_posts hook, this way:

    function exclude_shown($query) {
      if(is_admin()) return;
      $exclude_ids = get_shown_posts();
      if(!empty($exclude_ids)) {
        $query->set('post__not_in', $exclude_ids);
      }
    }
    add_action('pre_get_posts', 'exclude_shown', 100);
    

    (the get_shown_posts() above just gets the variable and yes, I’ll later refactori this in a class in order to avoid globals…).

    With its simplicity, this method works pretty well with any plugin/theme loops I’m using, as they just have to use any WordPress’s function leading to a WP_Query in order to exclude ids.

    However, I’ve noticed that YARPP still displays already shown posts.

    I’ve checked the code in YARPP_Core class and I’ve noticed that it makes use of WP_Query, however I’m not fully understanding how at the moment, because I see you’re passing $reference_ID as ‘p’ parameter, which should result in that specific post returned for the query…

    I was wondering if there’s a way to avoid related repetition when multiple related-posts boxes are displayed.

    Thanks!

    • This topic was modified 4 years ago by frafor.
    • This topic was modified 4 years ago by frafor.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author YARPP

    (@jeffparker)

    Hi @frafor

    I was wondering if there’s a way to avoid related repetition when multiple related-posts boxes are displayed.

    We’re working on an “offset” feature, where you’d be able to offset the results (for a set of recommendations). Similar to how WP_Query offsets results, but in this case it would be YARPP results.

    Is this what you’re looking for?

    The feature involves a rehaul of YARPP’s caching mechanism, hence it is taking a bit longer. Would you be up for “beta” testing it?

    Thread Starter frafor

    (@frafor)

    Yes that’s exactly what I meant. If you want I’d be happy to beta test.

    Another thing that’s bugging me is that it seems the plugin isn’t saving anything in wp_yarpp_related_cache, the table is just empty.

    Since the website is around 200.000 posts, I was wondering about the mechanism of the table cache.

    By looking at the plugin code, I understood that you prime the cache with the enforce() or update() method several time even when using display_related() function (the website uses custom positions with differents weight/settings in order to avoid using the same posts at the moment) although I did not clearly understand what “setup_active_cache()” does and what’s the difference between active_cache and cache props.

    However, above all, I cannot understand why the table does not get populated…

    • This reply was modified 3 years, 12 months ago by frafor.
    Plugin Author YARPP

    (@jeffparker)

    @frafor when you’re calling the function, are you setting custom params? It sounds like you are. There is a current known issue where if you do, cache gets skipped. This is also fixed in the “beta”.

    Can you please email me? jay at yarpp.com Would love to get your eyes on it.

    Thread Starter frafor

    (@frafor)

    Hi Jay, thanks for the opportunity, I’ve just sent an email!

    Thread Starter frafor

    (@frafor)

    Hey @jeffparker could you please follow up? Thanks!

    Thread Starter frafor

    (@frafor)

    Hi @jeffparker, is there any update on this one?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘It seems the plugin does not exclude posts via pre_get_posts’ is closed to new replies.