Title: Parameters for yarpp_related() function
Last modified: June 4, 2021

---

# Parameters for yarpp_related() function

 *  Resolved [flofiwp](https://wordpress.org/support/users/flofiwp/)
 * (@flofiwp)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/parameter-3/)
 * Hi,
    1. where can i find a list what key / values can be added to yarpp_related()-
   > a **full list** with parameters? 2. what to add in the following to have “consider_extra”
   for Headlines (key / value) to have the same like when i do this setting in the
   backend in dropdown for headlines.
 *     ```
       <?php
           yarpp_related(
                   array('post_type' => array('post', 'news', 'focus'),
                       'show_pass_post' => true,
                       'past_only' => false,
                       'exclude' => array(),
                       'recent' => false,
                       'weight' => array('title' => 2, 'body' => 2),
                       'threshold' => 5,
                       'template' => 'yarpp-template-list.php',
                       'limit' => 3), false, true);
           ?>
       ```
   
 * Thanks in advance
    Flo
    -  This topic was modified 4 years, 12 months ago by [flofiwp](https://wordpress.org/support/users/flofiwp/).

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

 *  Plugin Support [Michael Nelson](https://wordpress.org/support/users/mnelson4/)
 * (@mnelson4)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/parameter-3/#post-14529989)
 * Hi [@flofiwp](https://wordpress.org/support/users/flofiwp/),
 * 1. I vaguely remember there used to be a list hosted elsewhere but it disappeared.
   So we’re looking through the code and creating some documentation for it.
 * 2. You have `'title' => 2` which is the same as “Consider with extra weight” 
   for titles. However, titles normally weigh in disproportionately less than the
   body or taxonomies because of how the MySQL full-text comparisons work. Eg if
   you set the match threshold to 1, and are only considering post titles, and two
   posts have the exact same post title, their relatedness score will probably be
   less than 1 (eg maybe 0.2) unless their titles are very long. So you might want
   to try putting even more weight on titles, like 4 or 5.
 * Here’s what we have for documentation so far (still in progress). Let me know
   if you still have questions with it:
 * ——————————-
 * YARPP allows the advanced user with knowledge of PHP to customize the display
   of related posts using a custom templating mechanism.
    Use the functions in `
   includes/related_functions.php`, notably:
 * * `yarpp_related`, which gets the HTML for the related posts and displays it
   *`
   yarpp_related_exist` which checks any related content exists, or * `yarpp_get_related`
   which returns the list of related posts (`WP_Post` objects)
 * Each of these functions will default to using the settings set on the YARPP admin
   page, but they can be overridden by using the first argument, `$args`. The following
   array keys can be passed in:
 * * `limit` int indicating how many related items to return. Eg `10` will return
   at most 10 related posts/pages/products etc.
    * `threshold` float indicating 
   the minimum level of “relatedness” in order for a post to be considered related.
   Eg 4 is reasonable if considered post bodies * `show_pass_post` boolean indicating
   whether to include password-protected posts. Eg `true` will include password-
   protected posts. * `past_only` boolean indicating whether to only include posts
   published before the reference post. Eg `true` means to only include posts published
   before the post for which we’re finding related content. * `weight` array with
   keys `title` or `body`, (whose value is an int), or `tax` whose value is an array
   whose keys are taxonomy names (eg `category` or `tag`) and their values are ints.
   Eg `array('title' => 2, 'body' => 1, 'tax' => array('category' => 1, 'taxonomy'
   => 2))`. The int values are multipliers, indicating how heavily to weigh each
   criteria. 1 is normal weight, 2 is extra weight. * `exclude` string|array list
   of term_taxonomy_ids. Any posts using any of those terms will never be included
   in related results. Eg `"1,2,3" and`array(1,2,3)` both indicating that any posts
   using terms with term_taxonomy_id 1, 2 or 3 (regardless of whether they are categories,
   tags, or any custom taxonomy) will be excluded from YARPP’s related results. *`
   require_tax` array whose keys are taxonomies (eg “category” or “tag”) and whose
   values are the number required to be considered related. eg `array('category'
   => 2)` means, in order for another post to be considered related, it must share
   2 categories in common with the reference post * `recent` string of [SQL interval](
   [https://www.mysqltutorial.org/mysql-interval/](https://www.mysqltutorial.org/mysql-interval/)).
   Only posts within that time interval will be considered. Eg `"1 WEEK"` or `"2
   DAYS"` * `order` string indicating a column on `wp_posts` to order by, then a
   comma, and whether to order in ascending (“ASC”) or descending (“DESC”). Eg `
   post_title,ASC` indicating to order by the post’s title, alphabetically (A to
   Z). * `post_type` string|array a string of a single post type, or an array of
   multiple post types to consider. Eg `"page"`, or `array("post", "page", "wc_product")`
 * `yarpp_related`, also uses the following:
 * * `domain` string suggesting who called this. Mostly for internal use.
    * `template`
   string which theme/custom template to use. Built-in ones include “list”, “thumbnails”,
   or the name of a file in your active theme starting with `yarpp-template-`. Eg`
   yarpp-template-videos.php`. * `promote_yarpp` boolean indicating whether to add“
   Powered by Yet Another Related Posts Plugin” below related posts.
 * Each function also accepts a `$reference_ID`, the ID of the post for which you
   want related posts. Defaults to using the `$current_post`.
 * Eg
    Show related posts, using all the settings set in the YARPP settings page:
 *     ```
       <?php  yarpp_related(); ?>
       ```
   
 * Show at most 4 related WooCommerce products based on their title and especially
   on their categories. Use the custom template
    `yarpp-related-wc-products.php`
   which you added to your active theme.
 *     ```
       <?php
       yarpp_related(
           array(
               'limit' => 4,
               'weight' => array(
                   'title' => 1,
                   'tax' => array(
                       'category' => 2
                   )
               ),
               'post_type' => 'wc_product',
               'template' => 'yarpp-related-wc-products.php'
           )
       );
       ?>
       ```
   
 * Check for posts related to post with ID 123, and loop through them in order to
   do some more custom logic.
 *     ```
       $related_posts = yarpp_get_related(array(), 123);
       if($related_posts){
           echo 'No related posts';
       } else {
           foreach($related_posts as $post){
               // $post is a WP_Post object.
               echo $post->post_title;
           }
       }
       ```
   
 *  Thread Starter [flofiwp](https://wordpress.org/support/users/flofiwp/)
 * (@flofiwp)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/parameter-3/#post-14545348)
 * Hi Michael,
    thanks a lot.
 * 1. What are the limits on weight for titles and bodies?
    you wrote, we can try
   to set weight on titles, like 4 or 5 Are values like 100 or 1000 also possible?
   What is the range?
 * 2. Pages and Custom Post Types normaly does not have Categories or Tags. What
   can you suggest if we want to exclude some Post and Pages and Custom Post Types
   from showing in YARPP? Add opportunity for pages and custom post types to add
   tags or categories and then disallow in YARPP setting in Backend either tags 
   or categories? Or do you have a better idea?
 * Thanks a lot and have a great day.
 * Flo
 *  [thespacecamel](https://wordpress.org/support/users/thespacecamel/)
 * (@thespacecamel)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/parameter-3/#post-14547024)
 * 1. Yes 100 and 1000 are also possible. But “consider titles” sets it to 1, “consider
   with extra weight” sets it to 2. So anything larger than 2 is unusual. While 
   using the standard theme, YARPP will show the scores for each related item. You
   could try disabling all but one weight and seeing what the scores look like, 
   to get a sense for how you’d like the algorithm to weigh each parameter.
    2. 
   In order to exclude all posts of a specific post type from “the pool” (ie, never
   suggest them), you, for now, need to use the new setting: [https://i.imgur.com/xQUZ6My.png](https://i.imgur.com/xQUZ6My.png)
   We’ll investigate making it so you can exclude post types using `yarpp_related`
   too, but that will require some development time and I’m not sure how quickly
   that will be done.
 *  Thread Starter [flofiwp](https://wordpress.org/support/users/flofiwp/)
 * (@flofiwp)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/parameter-3/#post-14548288)
 * Hi,
    thank a lot.
 * In 2. i thought about disallow certain **pages** by categorories or tags.
    For**
   posts** that schould be possible, see screenshot [https://imgur.com/a/9e0jbj3](https://imgur.com/a/9e0jbj3).
 * Is it possible to add tags or categories to **PAGES** and **custom post types**
   and then disallow in YARPP settings in Backend this entries with defined tags
   or categories? Or do you have a better idea?
 * Thanks
    Flo
 *  Plugin Author [YARPP](https://wordpress.org/support/users/jeffparker/)
 * (@jeffparker)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/parameter-3/#post-14580300)
 * p.s. documentation for YARPP functions() has been updated and published here:
   
   [https://wordpress.org/plugins/yet-another-related-posts-plugin/#installation](https://wordpress.org/plugins/yet-another-related-posts-plugin/#installation)
 *  Plugin Support [Michael Nelson](https://wordpress.org/support/users/mnelson4/)
 * (@mnelson4)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/parameter-3/#post-14581546)
 * > Is it possible to add tags or categories to PAGES and custom post types and
   > then disallow in YARPP settings in Backend this entries with defined tags or
   > categories? Or do you have a better idea?
 * Yes, you can use another plugin to add categories and tags to pages. Eg I used
   P[ost Tags and Categories for Pages](https://wordpress.org/plugins/post-tags-and-categories-for-pages/)
   successfully to do that once. But there seem to be other plugins that can do 
   that quite nicely. (If you’re handy with code snippets, I bet you could find 
   just the right bit of PHP code to do that too).
 * Does that help [@flofiwp](https://wordpress.org/support/users/flofiwp/) ?
 *  Thread Starter [flofiwp](https://wordpress.org/support/users/flofiwp/)
 * (@flofiwp)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/parameter-3/#post-14606642)
 * Hi all,
    thanks a lot for your help. We will try to adjust and try out all settings.
   Have a good week! Flo

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

The topic ‘Parameters for yarpp_related() function’ is closed to new replies.

 * ![](https://ps.w.org/yet-another-related-posts-plugin/assets/icon-256x256.png?
   rev=2549977)
 * [YARPP - Yet Another Related Posts Plugin](https://wordpress.org/plugins/yet-another-related-posts-plugin/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yet-another-related-posts-plugin/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/)
 * [Active Topics](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/reviews/)

 * 7 replies
 * 4 participants
 * Last reply from: [flofiwp](https://wordpress.org/support/users/flofiwp/)
 * Last activity: [4 years, 11 months ago](https://wordpress.org/support/topic/parameter-3/#post-14606642)
 * Status: resolved