WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. briankerrdesign
    Member
    Posted 1 year 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.

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

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

    Thanks

    http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/

  2. briankerrdesign
    Member
    Posted 1 year 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.

    Thanks

  3. briankerrdesign
    Member
    Posted 1 year 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:

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

    Posted 1 year 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

About this Topic