Forums

[Plugin: WordPress Related Posts] Exclude category from related pots (4 posts)

  1. maorb
    Member
    Posted 2 years ago #

    Hi,

    This plugin is great and gives the anser for what I need
    (You can see at the bottom of a post 4 items it displays in here -
    http://www.biosearch.co.il/biotech/1579-biotech-england )

    One thing is missing for me in this plugin, and is the ability to exclude categories from appear in the related items.
    Meaning, if I have one category (or more) which I don't want that its posts will be chosen in the realted, there is currently no way to do that.

    I'll be very happy to see that feature in a next release of the plugin.

    Thanks for the plugin,
    Maor.

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

  2. jetonr
    Member
    Posted 2 years ago #

    Hello maorb,
    we are both in the same position you have no idea how much im suffering to exclude a category to apera in related posts. My example is i have a video blog and i have a featured category which is selected plus the name of that singer and now my related posts are just a mess, nothing worked for me so far, i tried to exclude it but then posts don't show up. I am kinda stuck and i have arround 800 posts on my blog. If you find a solution please share it here.

  3. maorb
    Member
    Posted 2 years ago #

    @jentor, I still have no solution for that, and I hoped that the plugin developer will visit here and see some problems/requested and consider it for the next version...

    If you find a solution, I'll be also happy it would be shared here.

  4. aldolat
    Member
    Posted 2 years ago #

    I solved in this way.

    Open wp-related-posts.php and go to line 85. This line has this code:

    foreach ($related_posts as $related_post ){

    Below this line paste:

    $rel_post_cat_id = wp_get_post_categories( $related_post->ID );
    $mycat_to_ban = 1;
    if (in_array($mycat_to_ban, $rel_post_cat_id)) { continue; } else {

    Change number 1 in the second line according to your needs: this is the ID of the category to exclude.

    Now, scroll down to this line:

    $output .=  '</li>';

    Below this line, paste this:

    }

    to close the if loop we added before.

    Save the file and upload it to your server, overwriting the original one (or make a backup of this, first).

    The modification makes this: while the previous lines collect the posts under certain tags, the new lines of code verify if these posts have a given category. If they do have, they will be ignored and the plugin continue on the following record.

    The downside of doing this modification is that when the plugin will be updated, you'll lose these changes. So it's better to create a backup of the modified file so to re-add these changes when the plugin will be updated.

Topic Closed

This topic has been closed to new replies.

About this Topic