Support » Plugin: Yet Another Related Posts Plugin (YARPP) » Only related CPT on CPT's and only related Posts on Posts

  • Hello,

    I started using the YARPP on a site that I use custom post types. I register my CPT and I already see it on my “The Pool”, but my issue is the following:

    What I want to do is show only related posts on posts, and *only* related CPTs on CPTs.

    However, when I use <?php related_posts(); ?> only posts are shown (so if I add it to the single.php, that sort of fixes the first half of my issue) but when I use <?php related_entries(); ?> both related posts and CPT’s are displayed.

    I was wondering if there was any sort of <?php related_posts(type='XXXXX'); ?> variant that will allow me to add it on the CPT php page and display only related CPTs.

    The same idea will help sites that have different CPTs and want to display only matching CPTs.


Viewing 1 replies (of 1 total)
  • Hi @justrunlah,

    I think you could use the more generic yarpp_related() function to build your own custom related post query using ‘post_type’ option in you query arguments.

    You have to put a custom function in the functions.php file of your theme, something like this should work

    function custom_yarpp() {
      $custom_args = array(
            'post_type' => array( 'your-CPT-here' ),
            ... any other argument like 'treshold' or 'template' or 'limit' ...

    and then call your own function

    <?php custom_yarpp(); ?>

    in the single.php file or wherever you want.

    Basically it should work but I’m not sure since I don’t have tried it out.

Viewing 1 replies (of 1 total)
  • The topic ‘Only related CPT on CPT's and only related Posts on Posts’ is closed to new replies.