• Resolved Halimah

    (@halimah)


    Please help! How do I exclude a category from related posts using a function/shortcode. Using the dashboard won’t work me.

    On my site all posts belong either of 2 categories namely Problems and Solutions. (A problem can be related to many solutions and a solution can be related to many problems).

    So on the post page, I want to have 2 levels of Related posts.
    (1)Related posts(Problems)
    (2)Related Posts(Solutions).
    Now if I add “related_posts()” twice to my “single.php” file I have the two layers of the related posts that I want, but now what is left is to specify that the first one should exclude Solutions(Category2) and the second should exclude Problems(Category1).
    Thanks a lot

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Michael Nelson

    (@mnelson4)

    Hi @halimah, thank you for explaining your question quite thoroughly.
    First you’ll need to find the ID of the categories. Do that by going to the admin categories page, find the category for “problems”, hover over its ‘edit’ button, and you’ll see the URL it sends you to has a parameter called “tag_ID” (See https://i.imgur.com/HeEm8SL.png). That’s the category’s ID. Let’s assume “problems” is 123 and “solutions” is 456.

    Then use code like this:

    
    <h2>Problems</h2>
    <?php
    yarpp_related(
    	array(
    		'exclude' => [456]// exclude solutions
    	)
    );
    ?>
    <h2>Solutions</h2>
    <?php
    yarpp_related(
    	array(
    		'exclude' => [123]// exclude problems
    	)
    );
    ?>
    

    Does that make sense?

    Thread Starter Halimah

    (@halimah)

    Many thanks @mnelson4 !!!
    That is exactly what I need! ??
    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to exclude a certain category from related posts using a shortcode/function’ is closed to new replies.