Override Yet Another Related Post Plugin Settings (YARPP)

446 Views Asked by At

I set up the plugin to show 10 related posts in the options panel but I don’t want to show 10 posts everywhere; just in some places.

Is there a way to tweak <?php related_posts(); ?> to show a different number of posts aside from what I set in the options panel?

1

There are 1 best solutions below

2
user8230352 On

Try adding limit option in the $args array of the related_posts() function.

Update 1:

You also need to figure out how will the number of limit be determined. You could have a default number that is then overriden if some custom field exists with a value, something like:

  $my_limit=5;
  $get_limit=(int)get_post_meta(get_the_ID(),'RelatedPostsLimit', true);
  if ($get_limit>0)
    $my_limit=$get_limit;
  $my_args = array('limit' => $my_limit);
  related_posts($my_args);

So in above code, the default limit is 5. If you want the post to have a different value, add a Custom Field RelatedPostsLimit with that value.

Update 2:

You don't insert the code inside related_posts(), you remove the original related_posts() and replace it with the above code. :)