Yet Another Related Posts Plugin (YARPP)
[resolved] Request: Add argument to include posts (4 posts)

  1. briankerrdesign
    Posted 3 years ago #

    I have custom post meta to set a related post manually for certain posts to have more control. I would like to see your plugin accept an argument to force the inclusion of the post(s) (ar array of IDs) prior to generating related posts.

      'include_posts' => array(101,111,103), //post ids

    would return 101,111,103, then X, Y, Z, etc until limit.



  2. briankerrdesign
    Posted 3 years ago #

    Actually it may be better to display the manual posts first, then query with YARPP with 'post__not_in' to exclude them.

    I will prob modify the plugin to do this for now.


  3. briankerrdesign
    Posted 3 years ago #

    Modified class-cache:

    $options = array( 'threshold', 'show_pass_post', 'past_only', 'weight', 'require_tax', 'exclude', 'recent', 'limit', 'post__not_in' );
    // WHERE
    $newsql .= " where post_status in ( 'publish', 'static' ) and ID != '$reference_ID'";
    if ($post__not_in)
    	$newsql .= " and ID not in (".join(',', $post__not_in) .")";

    Modified call:

       'post__not_in' => array(270),//ignore posts
  4. mitcho (Michael Yoshitaka Erlewine)
    Plugin Author

    Posted 3 years ago #

    Thanks for taking a deep dive into YARPP! :D

    I did something like this for a client, without modifying the YARPP core code. You can simply use the the_posts filter and make sure you're only modifying the output when it's a YARPP loop.

    Something like:

    add_filter( 'the_posts', 'yarpp_add_entries', 10, 2 );
    function yarpp_add_entries($posts, &$query) {
    global $yarpp;
    if ( !$yarpp->cache->is_yarpp_time() )
    return $posts;

    // check query vars for reference_ID
    // construct extra posts as array, using get_posts()
    $extra_posts = get_post( $special_query );

    return array_merge($posts, $extra_posts);

    Hope that helps!

    In addition, if you're looking to exclude certain posts in your output, I suggest you do that using a YARPP custom template: just check the IDs in the template, and not print the output if it's one of the ones you want to exclude.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Yet Another Related Posts Plugin (YARPP)
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic