Share/Bookmark

Related Posts Showing Unrelated Pages

I finally got around to hacking the Related Posts plugin for WordPress. I love the plugin, but on some posts it listed pages like my contact form or email newsletter confirmation as related pages. None of my "pages" are related to any of my posts and I don't want my pages listed as related to my posts.

I looked on the Wasabi site (home of the Related Posts plugin), but didn't find anything other than a comment from someone with the same problem. The question was posted three months ago and it was never answered. So, I looked at the plugin code and came up with a quick solution.

To disable pages in your related results, just follow these five steps:

  1. Log into the admin area of your WordPress blog.
  2. Click on Plugins, then click on Plugin Editor.
  3. On the right is a list of your plugin files. Click on Related Posts.
  4. In the Editing related-posts.php text window, scroll down until you find this line:

    . "AND (post_status IN ( 'publish', 'static' ) && ID != '$post->ID') ";

    Its almost half way down (its a few line below // Primary SQL query). If you are using Windows, you can do a search by hitting ctrl-F and searching for static. It's line 92 if you are using a text editor on your computer.

    Change 'publish', 'static' to just 'publish'
    Static refers to pages and publish refers to posts. The new line should read:

    . "AND (post_status IN ( 'publish' ) && ID != '$post->ID') ";

  5. Click the Update File button and you are done.

That's it. Your pages will no longer be listed as related to any of your posts.

This entry was posted in How-to, WordPress. Bookmark the permalink.

13 Responses to Related Posts Showing Unrelated Pages

  1. kris says:

    Thanx! This was exactly was I was looking for!

  2. kris says:

    This does work, but for me it messes up the plugin control menu.

  3. Ken Cheung says:

    Interesting. The plugin control menu remains the same for me.

  4. Ken -

    Thanks for this fix (enhancement). I would like to omit posts from a certain categories, but don't have the knowledge or skills to make it happen. Any ideas?

    -David

  5. Ken Cheung says:

    David,

    I took a look and could not find an easy way to do. A hack will require using a table not currently used in the related posts plugin. I'll see what I can do over the weekend (if I have time).

    Ken

  6. Ken –

    Thanks a bunch. I guarantee that a workable solution will yield a PayPal Transfer to buy your morning coffee and bagel, or a six-pack of beer (maybe just domestic), or the #9 Menu at Taco Bell. Whatever works for you. :-) It is not much, but a way to show a little appreciation. If it turns out to be to much work, thanks for giving it a shot anyway.

  7. Ken says:

    OK David. It was too long to post in a comment so I created a new post:

    http://izachy.com/2006/09/03/excluding-categories-from-the-related-posts-plugin/

  8. Pingback: Showing Posts When There’s No Related Posts

  9. Pingback: Similar Posts WordPress Plugin

  10. mod says:

    kris – "This does work, but for me it messes up the plugin control menu."

    I would assume that you might have cut or pasted in more then was needed. I would copy a new copy of the plug-in over again, then try re-editing.

  11. Che-Cheh says:

    Hi there, do you know where to paste ?
    I've tried to paste it in index.php and single.php but it's not correct.

  12. Ken says:

    Che-Cheh, if you are talking about the hack mentioned about, you make the changes in the plugin file itself. If you are talking about the code to call in the plugin, you can put it almost anywhere you want…index.php, single.php, home.php, etc

  13. Thanks very much Ken, I've been wanting to implement the related posts plugin but until now it didn't work like I wanted it to. I used your code to eliminate category 1 (my pages — about, disclaimer, etc.) and that did the trick. I don't know why but when I initially changed ( 'publish', 'static' ) to
    ( 'publish' ) it didn't make a difference. It could be the new version of wordpress (2.1.2) though, since your post was last year. Either way it's settled now. :)

    Thanks again, I'm very happy to have this working!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

iZachy Newsletter

Don't have time to visit iZachy everyday? Then sign up for my free newsletter. I'll send you an email when I have something to share with you. Your email address will be kept confidential and I will not share, sell, or rent it to anyone. You can unsubscribe at any time by clicking a link in the email.

Enter your email address to sign up for my newsletter:
  

Or you can also sign up for our blog feed.