A Better Related Posts Plugin

There are many plugins that find related posts for WordPress, and I was happy to use one of them in the past. However, WordPress evolves. One of the biggest change was the addition of custom post types. They are very useful and I use them a lot for my own and for client sites. And this is where every related posts plugin I tested failed: They don't support custom post types.

While reviewing the code of several plugins I decided that the Right Thing would be to write a new plugin from scratch. And that's what I did. Key features:

  • Depends on PHP5 and MySQL5
  • Option to add related posts to the RSS feed
  • You can theme the output as you like
  • Use fulltext indexes for good performance
  • Does caching through post meta, this means zero additional database queries
  • Incremental scoring for sites with many posts
  • Find related posts, pages and custom post types
  • Use different configurations at the same time, useful for different post types
  • Internationalized, OO, hopefully well documented and readable
  • Score relationships by various MySQL relevance scores or term relationships

Use tags, categories or custom taxonomies

The readme.txt contains extensive documentation. It is possible to create completely custom views of related content, including post thumbnails, date, excerpts etc.

Downloads are available at WordPress.org.

WordPress plugin demos are disabled as I don't use WordPress on this site any more.

Published on Oct. 31, 2010 at 2:08 p.m. by Nicolas and tagged related posts, related content, custom post type, WordPress plugin, custom taxonomy, WordPress. You can follow the discussion with the comment feed for this post. Feeling generous? Donate!

253 comments

  1. avatar
    wrote this comment on

    I've downloaded and activated this plugin but it's not showing up on my pages. Am I missing something??

    1. avatar
      wrote this comment on

      Well I figured out how to make it on the post BUT it's showing 8 queries in 0.0966 seconds, current offset 0 after the words Related Content. How do I get rid of that and the numbers after the related post link??

      1. avatar
        wrote this comment on

        You can turn this information off on the options page. It is only displayed to logged in admins, not all visitors.

  2. avatar
    wrote this comment on

    i've activated this plugin on WPMU and i get error :
    "There is no fulltext index for wp_1_posts.post_content"
    "There is no fulltext index for wp_1_posts.post_title"
    Am I missing something?

    1. avatar
      wrote this comment on

      Oh, did you perform a network activation of the plugin? I guess that would trigger the error on all blogs but the one you activated the plugin on.

    2. avatar
      wrote this comment on

      Which MySQL version are you running? The fulltext index should be created at plugin activation, and IIRC the plugin checks for the indexes every time you access the options page.

    3. avatar
      wrote this comment on

      If you did a network-wide activation please try again with the current trunk version: http://wordpress.org/extend/plugins/better-related/download/ (trunk should appear in a few minutes)

      1. avatar
        wrote this comment on

        thanks nicolas, I am very pleased and will patiently wait

  3. avatar
    wrote this comment on

    Just getting started with this plugin and I need to know what values the multiplier fields take? is it just 0/1 or up to where? Need a bit more info on this...

    1. avatar
      wrote this comment on

      They are simply integers and there's no limit. Actually, I should probably make them floats...

      1. avatar
        wrote this comment on

        ok, thx. just wondering as by default two fields had 1 the rest had 0... will experiment a bit... I guess everyone has figure out his own values depending on what he uses most, categories/tags/etc..

  4. avatar
    wrote this comment on

    ok, now totally confused. I read above: The scoring methods... so it seems the multiplier fields are not used at the same time?
    Where do I select a scoring method?

    1. avatar
      wrote this comment on

      Each scoring method has it's own multiplier, that you can set on the options page. Setting it to 0 will disable that scoring method. Use the_related_analyze(); to analyze which scoring methods are relevant for you. Hide that from normal visitors on the frontend though, use current_user_can().

      1. avatar
        wrote this comment on

        I really don't understand. what do you mean relevant? I think all are relevant I just need to assign them a particular score depending on how goo the results they yield are? So if a particular scoring method gives me good results I raise its score, right? maybe lower or disable those that don't give good results and be happy with the resulting mix?
        btw. what are keywords? meta-keywords?

        1. avatar
          wrote this comment on

          Please check the readme.txt. If things aren't clear there I will update the documentation.

  5. avatar
    wrote this comment on

    I seem to be having some problems with the automatic injection into pages. the pages where I have hte problem, all have some sort of shortcode, either gallery shortcodes or other ones in them... it works for pages without shortcodes though. And I know there is related content because I used he_related_analyze(); to check it out...

    1. avatar
      wrote this comment on

      I have never seen this problem.

      Please disable or delete all plugins and switch to the default theme. The default theme in WordPress 3.0.x is Twenty Ten. After making these changes does the problem still occur?

      If not, switch the plugins on one by one and tell me which one creates the problem, I'll have a look.

  6. avatar
    wrote this comment on

    Hello, I got 2 posts in the same category. On the newer post the older one is under "Related Posts". But on the older posts the newer one doesn't appear. How do I make this work?

    1. avatar
      wrote this comment on

      Hi Patrick, you can lower the score necessary to display results or show more related posts. The relevance score varies, depending on which direction the relatedness tests are performed.

      1. avatar
        wrote this comment on

        Thanks for your advice. Lowered it to about 35 and it works now. :)

        1. avatar
          wrote this comment on

          Ok, great! I'm currently working on a new feature to set related posts manually as well. Hope to release it soon.

          1. avatar
            wrote this comment on
            Any news on that topic? :-) Do you need some financial support to achieve that dev-goal?

            Best, Rico
            1. avatar
              wrote this comment on
              That's an interesting question.. what do you have in mind?
  7. avatar
    wrote this comment on

    hey, I am very glad to have found your plugin. it looks awfully useful, especially given all the fine tuning between post content, title, category and such!
    – my problem:
    I have included "" in my sidebar. while the plugin shows "related" posts under the single post, it at the same time says "no related" in the sidebar...
    ... can you help? thanks!

    1. avatar
      wrote this comment on

      PS: “” meaning the php-template-tag

      1. avatar
        wrote this comment on

        Hi oliver, I assume you meant the_related() ? You can pass the post ID as first parameter in the sidebar, that should work.

        1. avatar
          wrote this comment on

          thanks for the feedback, Nicolas!
          – but this hasn´t changed the display.
          ...at least if you were meaning taking out the »get_the_ID(),« line of the call-function. still I get the "no related" in the sidebar, though results are there with the same code-lines [including the ID call] in the body...

          [on the sidetrack: still what the parameters of what I put in the sidebar actually do control is the display-behavior of the "automated display in post"-function if that setting is turned on... so there seems to be something going on in the background... :-}]

          PS: … what actually happens when I take out the ID-line, is that the sidebar display switches to the heading filled-in in the custom-presets section of the plugin (even though automatic display for posts is turned off there)

          1. avatar
            wrote this comment on
            Hi
            I have the same problem and still no solution
            1. avatar
              wrote this comment on
              I'm not even sure what the problem is.
          2. avatar
            wrote this comment on

            Please keep in mind that I can't see your code, I don't really know what you are trying to do. It's probably filtered away because you used php tags.

            http://codex.wordpress.org/Function_Reference/get_the_ID : This tag must be within The Loop.

  8. avatar
    wrote this comment on

    Hello! I tried to install this plugin using WP Admin and through FTP too, but It keeps showing:

    There is no fulltext index for wp_posts.post_content
    There is no fulltext index for wp_posts.post_title

    What can I do to fix it? Thanks!

    1. avatar
      wrote this comment on

      Hi, I think this is a bug. I've just released 0.4.3 which should hopefully fix this problem. you need to deactivate the plugin and activate it again.

      1. avatar
        wrote this comment on
        It could also be that he was using InnoDB instead of MyISAM as his table engine. This was the case for me at least.

        A simple
        ALTER TABLE wp_posts ENGINE = MyISAM;
        then disabling and reenabling the plugin fixes this right up.
      2. avatar
        wrote this comment on

        Hi Nicolas! I did the upgrade (deactivated and them the upgrade), but the error remains. I also tried the SQL do create the fulltext, but error again:

        Query : CREATE FULLTEXT INDEX content_index ON wp_posts (post_content)
        Error Code : 1214
        The used table type doesn't support FULLTEXT indexes

        What should a do now? Thanks

      3. avatar
        wrote this comment on

        Ah, I see. Your MySQL tables aren't using the MyISAM storage. Are you the database admin? If yes, it might be possible to change the storage engine, see <a href="http://dev.mysql.com/doc/refman/5.1/en/alter-table.html" rel="nofollow">this page</a>.

        MyISAM is the default storage engine for MySQL. I guess I could build engine detection into the plugin and create new tables if necessary... but this would create quite some overhead. I'll look into this for the next release, but at the moment I think it's rather unlikely I will add such a feature.

        1. avatar
          wrote this comment on
          2.5 years later and I'm finding the same issue... hmm. My sense is that changing my entire MySQL setup to make this plugin run wouldn't be worth it...

          Interestingly, the plugin appears to still work in the frontend...

          should I be concerned about performance (or security?) issues if this error message persists in the backend?

          Thanks,
          1. avatar
            wrote this comment on
            That's bizarre... maybe innodb got fulltext searching by now, not sure..
        2. avatar
          wrote this comment on

          I did the change, now It's MyISAM and the error n plugin's page disappeared, but all posts from my custom post_type "Eventos" keeps showing "No related content found."
          I'm using almost all the default configuration values, look: http://awesomescreenshot.com/09f3ksl22

  9. avatar
    wrote this comment on

    This plug-in looks great !

    However I've got the same problem than ubas for my blog :
    http://windows-mobile.fr

    Could you help me please ?

    Best regards

    1. avatar
      wrote this comment on

      I've installed 0.4.3 (from scratch as I've just discovered your plug-in ;-) ) but I've got the same issue...

    2. avatar
      wrote this comment on

      Which MySQL version are you running? It has to be 5 at least.

      If you are on v5 try to run the command "CREATE FULLTEXT INDEX content_index ON wp_posts (post_content);" in phpmyadmin or another mysql client. Do you get an error, if yes which?

  10. avatar
    wrote this comment on

    excellent plugin.

    however, how do i stop the current article being the first related post? i don't want users going round an endless loop.

    my current article always has a score of around 51000, and is always displayed as the first related post. all following articles are between 125 and 50 (my min score setting).

    i would like to list "other" related pages, and not say "you might like to read the article you're already reading. it's relevelant!" ;)

    thanks for your help.

    1. avatar
      wrote this comment on

      Hmmmm, that's odd. How is the list generated on your site? Do you just use the built-in auto-add feature? This shouldn't be happening.

  11. avatar
    wrote this comment on

    Tag to Taxonomy Multiplicator okay, but why not Category to Taxonomy Multi? If I got two posts with the tag "action" then they are linked. Fine. But if I got two posts of the same category (some posts have more than one cat, dont know if thats a problem) then they should also appear. They do not. Only if I go down to 10 % match and then it shows too much stuff.

    1. avatar
      wrote this comment on

      Yes, there's room for improvement for the term to term relationship scoring. I plan to work on that for the 0.5 release.

      It's "Term to taxonomy multiplier" btw, and should probably be called "Term to term multiplier", so it applies to tags, categories and any custom taxonomies.

      Personally, I don't think that just sharing a category should make a post related automatically, but that's what the Term to tax multiplier is for, you can set it to something higher.

  12. avatar
    wrote this comment on

    Could you give an example of your manual inclusion code that defines a specified custom post type and custom taxonomy please?

    For the life of me I can't figure out how to modify the manual inclusion code to specify the custom post type and custom taxonomy that it should use.

    1. avatar
      wrote this comment on

      The section "How to use different configurations at the same time" in the readme is all you need. The plugin will use the custom taxonomy your post type uses anyway. The usetax parameter is only for searches across different taxonomies, I assume you don't need that?

      1. avatar
        wrote this comment on

        Thanks Nicolas. I tried the code you mentioned (below) and it works. But it's not a loop, so I can't add thumbnails to my related recipes. Is there a way with this plugin to make a custom loop that <a href="http://codex.wordpress.org/Custom_Post_Types#Querying_by_post_type" rel="nofollow">queries a custom post type?</a>

        'if ( function_exists( 'the_related' ) ) { the_related(
        get_the_ID(),
        array(
        'usept' =&gt; array(
        'recipe' =&gt; true
        ),
        'storage_id' =&gt; 'better-related-recipe'
        )

        );
        }'

        1. avatar
          wrote this comment on

          Seriously? Did you miss the "How to build a custom loop of related posts" section? Just add your post type to $args.

          1. avatar
            wrote this comment on

            That last sentence is what I needed. We're not all programmers. Of course I saw the section, hence my original question of how to define the custom post type to use. And the answer is to add your custom post type to $args. Thx.

            1. avatar
              wrote this comment on

              Great :-)

  13. avatar
    wrote this comment on

    Hi Nicolas. I've implemented your great plugin, but in the results i see private declared articles too. Thats realy not good. Ok, the articles are not accessible for the users without the rights, but i do not want, that the headers are showed in my public area.
    how i can prevent this? Is a secret option available for this?
    best regards
    Michael

    1. avatar
      wrote this comment on

      Hi Michael. No, this is not configurable at the moment, but I will add this feature in the next release.

      If you're comfortable with PHP you could edit lines 300 and 463 in inc/scorer.php to exclude them from the SQL query as a quick fix.

  14. avatar
    wrote this comment on

    Hi Nicolas,

    I have a quick question that your plugin may cure but I'm not sure, I was hoping you could give me some insight.

    On this page http://waterworks-lamson.com/authorized/ I have an "authorized dealer" search plugin set up that when you type the state in the search box "california" it will return the results (post)california then you have to click on that to get to the post.

    I would like to bypass the results page that you need to click on and go directly to the post. Is this possible?

    And..... I would like to only have the search on this (page).

    I hope you can help.... boy do I need it!

    Thank you for your time!

    Brent

    1. avatar
      wrote this comment on

      Well, I think that should be possible, but it depends a little on how your site was coded. I assume you had somebody build it for you, you could just ask that person to look into this or you can use my contact form if you're interested in hiring me :-)

  15. avatar
    wrote this comment on

    Hello Nicolas,

    I am trying to display custom post type thumbnails, but I can't get this to work.

    Could you tell me how to re-write frontend.php (L. 480...) to display my custom post type thumb?

    I call my thumbs like this:
    cp_get_image($post-&gt;ID, 'ad-thumb', 1);

    I would really appreciate the help... I just can't get it to work :-(

    Thanks,
    C.

    1. avatar
      wrote this comment on

      Hi, did you have a look at the readme.txt? It has examples for custom loops. cp_get_image() doesn't seem to be a wp function btw.

      1. avatar
        wrote this comment on

        Hello,

        Yes I looked at your read me file but I can't get your example to work with custom post type images, which is the whole point of using your plugin versus YARP.

        cp_get_image() is a custom function that works when I need to display thumbnails in the sidebar or anywhere in the posts so I know that it can be called. I'm just really fuzzy about this whole custom post system so I would appreciate the guidance.

        I'm sure many more people will be interested in knowing how to do this over time ;-)

        Thanks for understanding,
        C.

        1. avatar
          wrote this comment on

          Custom post types aren't different from normal posts in regard to thumbnails.

          The "How to build a custom loop of related posts" in the readme.txt features post thumbnails. Maybe I can help more if you ask a more specific question.

          Oh, and you should not hack the plugin files btw, everything can be done in a custom loop. If you find any limitation let me know and I'll see what I can do.

  16. avatar
    wrote this comment on

    Hi Nicolas, I manage a site with about 3000 posts: http://personensuchpool.de but no related posts will be shown. All your requirements are fulfilled: php5, mysql5. I deactivated other plugins but nothing and there are a lot of related ones. What do I wrong.
    Thank you
    Dietrich

    1. avatar
      wrote this comment on

      Sorry, dämlichen Fehler gemacht, 2 Plugins verwechselt. Nun muss ich nur noch anpassen. Klasse Plugin, danke
      Dietrich

      1. avatar
        wrote this comment on

        :-D Kein Problem! Bitteschön!

  17. avatar
    wrote this comment on

    Cool plugin! I set up a custom loop with thumbnails. Is there a way to show related items with thumbnails before those that don't have one? Or to show only related items that have thumbnails?

    1. avatar
      wrote this comment on

      Yes sure, see http://codex.wordpress.org/Function_Reference/has_post_thumbnail for the latter. For the former you can store the posts with thumbnail in an external var or loop through your posts twice, see http://codex.wordpress.org/The_Loop

      1. avatar
        wrote this comment on

        Thanks. For some reason I couldn't get has_post_thumbnail to work wherever I tried to integrate it (I must've not found the proper place to use it in my custom loop.) But I was able to get it to work by adding this to the array of argument:
        ''meta_key' =&gt; '_thumbnail_id','

        From: http://wordpress.org/support/topic/display-the-post-only-if-thumbnail-is-set-up

        Your other option sounds cool, but is way over my head. Just wanted to post this in case it helps others.

        http://wordpress.org/support/topic/display-the-post-only-if-thumbnail-is-set-up#post-1769764

        One last question, if you’d be so kind.

        If, for instance, only 2 related posts are displayed with thumbnails, can a custom loop be set up to automatically display 3 random posts with thumbnails to fill out all 5 areas?

        This may be a hard one.

        1. avatar
          wrote this comment on

          This plugin doesn't show random posts. But you can probably just store the post IDs of the first loop and start a second loop that excludes those posts. See http://codex.wordpress.org/Function_Reference/query_posts for random order IIRC

  18. avatar
    wrote this comment on

    I got it to work! Thought I'd share. I set up two loops, and somehow figured out how to set up a counter, so that the second loop returns only enough thumbnails to fill in 5 total thumbnails in case fewer than 5 related items exist. This way there are always 5 thumbnails and it looks great. It's only missing one thing, an argument to exclude the current post itself on which these are displayed from being returned as a thumbnail. But I tried everything and haven't found an argument that works. But it's still pretty darn well. Works for me. Thought it might help others and wanted to share.

    <strong>Edit</strong> Sorry, I had to remove your code. WordPress is really lousy when it comes to code in comments. Can you pastebin your code? I'll be able to have a look then.

    1. avatar
      wrote this comment on

      http://pastebin.com/kMc78FEj

      Give this link a try. My code looks a little messy, so if you see a way to improve upon it, like excluding the current post, I'd love to hear.

      1. avatar
        wrote this comment on

        BTW, when I turn on WordPress' debug in wp-config, my code gives this notice:

        Notice: Undefined variable: do_not_duplicate

        The code obviously works. So it's not a big deal. But should I just set the variable equal to zero right before using it, so it's defined?

        1. avatar
          wrote this comment on

          Well, notices aren't so bad. Just define the variable before trying to access it. Like, $foo = array() etc.

  19. avatar
    wrote this comment on

    Hi, I have using your the plguin. but it is show some wrong in admin panel. I am using mysql 5.1.54 and your plguin v0.4.3.3.

    "There is no fulltext index for wp_posts.post_content
    There is no fulltext index for wp_posts.post_title"

    1. avatar
      wrote this comment on

      Your database probably doesn't use the MyISAM engine, which is the default for mysql. You should probably talk to your admin/hosting provider. This plugin will only support databases that support fulltext indexes.

      See the comments by Leonardo for how to test which MySQL engine you're using.

    2. avatar
      wrote this comment on

      I just see that InnoDB has been made the default with MySQL 5.5.

      You could <a href="http://dev.mysql.com/tech-resources/articles/storage-engine/part_1.html" rel="nofollow">change the engine for wp_posts</a>.

      I guess I could easily attempt to change the storage engine of the relevant table after asking for user permission. I'll be include such a feature in the next release.

      1. avatar
        wrote this comment on
        Current version still has this problem with:
        There is no fulltext index for wp_posts.post_content
        There is no fulltext index for wp_posts.post_title

        I am using WP 3.2 RC3, and since 3.2 minimum requirements for Wordpress is MySql 5.0. I guess that's the problem, engine is InnoDB on all tables... be sure to fix it before 3.2 goes official :)

        I went to PHPMyAdmin and changed the engine of 'posts' table to MyISAM, and your plugin works perfectly now :)
      2. avatar
        wrote this comment on

        I think should use InnoDB,so mysql offical choose. we have to use InnoDB. I have plan update to mysql v5.5. I have try mysql5.1 to5.5. but it is has some issue.

      3. avatar
        wrote this comment on

        I'll have to look into the reasons why MySQL decided to use InnoDB by default. If you can't switch the content table to MyISAM this plugin isn't for you, at least not at the moment. This plugin uses fulltext indexes for the search, which InnoDB doesn't have. I'll keep an eye on the future development.

        By the way, MySQL changing the default storage engine will only affect new databases, not existing ones.

      4. avatar
        wrote this comment on

        I remember mysql offical said will give up MyISAM. This is a long time ago what they have decided. So I am use InnoDB. though I like the MyISAM easy backup.If I use MyISAM,then will not easy for mysql upgrade.

        now your plguin work in my WP blog. but I do not know what effect that error.

  20. avatar
    wrote this comment on

    thanks Nicolas for this plugin...

    Currently I am using YARPP but I am planning to replace that with the plugin developed by you...i have one question though (a noob here)..I want to use a thumbnails in the related posts..can you guide/suggest me how to do that.

    Thanks

    1. avatar
      wrote this comment on

      Do you know how to build a normal loop with post thumbnails? Do you actually use the post thumbnail feature? If so, there is an example of a loop in the readme.txt iirc.

  21. avatar
    wrote this comment on

    Hello Nicolas,

    I'm having this problem with the plugin:

    I'm trying to use the plugin to a post type called "Events", but it is showing only the posts of "events" are marked with the same taxonomy. I want him to show all posts "Events", regardless of their taxonomies. There's how to do this?

    Thanks for the plugin.
    Hug.

    1. avatar
      wrote this comment on

      Did you check the analyze function yet? Maybe the contents of your events just aren't related enough? Also, the plugin only checks relatedness in the post_content field, not in any custom fields.

  22. avatar
    wrote this comment on

    hi

    1st of I have to thank u for the great plugin ! it's really useful ! I got question :

    How can I insert it in my template and remove the automatic related links just after the post ? I wanna place it after the post block

    Thanx

    1. avatar
      wrote this comment on

      Check the options page, or the readme.txt.

  23. avatar
    wrote this comment on

    Hi nicolas,
    your plugin is nice, but after I installed for about two weeks, I can't display my preview post, even single post I.

    the error massage:
    Allowed memory size of 33554432 bytes exhausted (tried to allocate 30720 bytes) in .../public_html/wp-content/plugins/better-related/inc/scorer.php on line 382

    now I'm deactivating the plugin and waiting your advice.

    thanks

    1. avatar
      wrote this comment on

      Hi,

      you'll have a hard time trying to get any plugins to work with 32MB. You should probably look into getting a better hosting package with more RAM.

      You could try to reduce the query limit and to activate incremental scoring.

      1. avatar
        wrote this comment on

        Exactly the same experience. PHP allowed size is same as above. Every othee plugin works like a charm. I tried to lower query limits. It allowed me to lower them to 100 (Query limit) and 200 (Total Query limit) , I also activated incremental scoring. But doesn't work. Failed to show the page at all. It started when the number of posts raised. There are currently about 8000 posts in the blog. Any suggestion ?

        1. avatar
          wrote this comment on

          Well, I don't think this is something I can do much about. 32MB is really not enough to run many plugins. You could try the YARP plugin, maybe that works.

  24. avatar
    wrote this comment on

    Hi, there is a problem with the admin backend: it doesn't seem to escape the values it tries to insert into the form.

    Try using

    &lt;strong style="color:red"&gt;Related Posts&lt;/strong&gt;

    in the title field. The value is saved correctly but when the form shows up again its broken.

    1. avatar
      wrote this comment on

      Thanks for reporting this, I'll look into it ASAP.

  25. avatar
    wrote this comment on

    Hi Nicolas,

    I just installed your plugin and was very impressed since it actually recognized the custom posts and ads through the admin settings panel in the classified theme that I'm using (ClassiPress from AppThemes), although when I test drive it on the front end, I always end up with "No related content found" despite checking all the custom fields in the settings and this theme explicitly uses the custom post types yet no results :(

    post page ad_listing
    category post_tag post_format ad_cat ad_tag
    I'm on a dedicated server so no DB issues, using WP 3.1 latest update and using ClassiPress theme. Admin preview: http://www. appthemes.com/demo/?theme=classipress-admin

    1. avatar
      wrote this comment on

      Did you try the analyze tag yet? It's usage is described in the readme.txt.

      1. avatar
        wrote this comment on

        No I haven't and I just realized that the plugin actually worked but only under the main Blog posts and not the custom posts and custom categories, I'll try the Analyze tag attempt and update you with the outcome.
        Thanks Nicolas.

  26. avatar
    wrote this comment on

    Hi Nicolas,

    Do you know what this warning might mean in regards to the code listed below it?

    Warning: array_keys() [function.array-keys]: The first argument should be an array

    $posts = array_slice( array_keys( $scores ), 0, 5 ); // keep only the the five best results

    Is this happening because no related items are found?

    1. avatar
      wrote this comment on

      Hm, I'm not sure right now, but I'll look into this.

    2. avatar
      wrote this comment on
      Hi Nicolas.
      Thank a lot for your superbe plugin - very helpfull.
      Unfortunately I am faceing the same problem like Thompson getting the following error messages:
      Warning: array_keys() [function.array-keys.php]: The first argument should be an array
      Warning: array_slice() expects parameter 1 to be array, null given
      I copied your code example as it is from the readme.txt file and added a custom post type.
      I would highly appreciate your help in this matter.
      Thanks, Benjamin
      1. avatar
        wrote this comment on
        Please pastebin your code and post a link.
        1. avatar
          wrote this comment on
          Hi Nicholas Thanks for your quick answer. I have the following code inserted:
          <?php
          $scores = the_related_get_scores($post->ID, true);
          $posts = array_slice( array_keys( $scores ), 0, 6 );
          $args = array('post__in' => $posts, 'post_type' => 'teppich', 'posts_per_page' => 6 );
          $my_query = new WP_Query( $args );
          if ( $my_query->have_posts() ) {
          while ( $my_query->have_posts() ) {
          $my_query->the_post();
          $url = get_bloginfo('url');
          $directory = get_bloginfo('template_directory');
          $orderid = get_post_meta($post->ID, 'order-id', true);
          echo '<li><a href="' . $url . '/teppich/' . the_slug( get_the_ID() ) . '"><img src="' . $directory . '/teppiche/' . $orderid . '.jpg" /></a></li>';
          } } else { echo "No posts found..."; } ?>


          An example of the page you'll find on http://karpet.ch/redesign/teppich/almaty/
          I adjusted the code slightly, but even with the code from your readme.txt file, i got the same problem.
          Below the the «Diese Shyrdaks werden Ihnen auch gefallen» 6 related items should be listed within the slider.
          The weird thing is, that sometimes it works but most of the time i get the above mentionned error message.
          Thank you so much for your kind help. A donation for your superbe plugin will be for sure..! ;o)
          Regards from Switzerland,
          Benjamin
          1. avatar
            wrote this comment on
            I think the problem is that the_related_get_scores() returns null (or false, not sure how I coded that). So you should probably check if $scores is_array() before you run the rest of the code.

  27. avatar
    wrote this comment on

    Hi, is it possible to use it with special post (post type). I'm using post type to differ products from regular blog both in front and back end.

    1. avatar
      wrote this comment on

      Yes, please check the readme.

  28. avatar
    wrote this comment on

    Hi Nicolas, I've already read the readme.txt file and all comments above, but I've a doubt about using taxonomy.

    Say I have 2 different posts types, A and B, and a custom hierarchical taxonomy named "type", defined on both. If I use a configuration like this:

    http://w3b.pastebin.com/v0erkGFN

    should I get a selection of related posts from A to B (and viceversa), only if they SHARE THE SAME TERMS under "type" taxonomy, ?
    In other words, for a post in A (or B), can I get a list of related posts, but only selected among B (or A) posts classified with the same terms under the same taxonomy?

    Thanks in advance, Daniele.

    1. avatar
      wrote this comment on

      Hi Daniele,

      hm, I don't think so. It's been a while I've worked on this code but I don't think you can query only one post type.

      What you could do is to filter by post type in the loop that displays the results though (I guess).

      For the next major release I wanted to rewrite the taxonomy scoring anyway, so I'll look into this. Thanks for the idea.

  29. avatar
    wrote this comment on

    I can't activate che plugin. I'm using the WP 3.1 and the plugin Version 0.4.3.3. I also have Custom Post Type UI, Custom Field Template, Header and Footer and Tweet Import activate.

    #######################

    Plugin could not be activated because it triggered a fatal error.

    Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /nfs/c01/h16/mnt/6224/domains/sodastudio.it/html/wp-content/plugins/better-related/better-related.php on line 44

    1. avatar
      wrote this comment on

      I think you're using PHP4? The plugins needs PHP5.

      1. avatar
        wrote this comment on

        You are right, I have php4.
        Thank you.

  30. avatar
    wrote this comment on

    hi nicolas - huge thanks for making a plugin that works with custom post types - quick question:

    my client has 3 distinct areas on the site - 3 blogs if you like - I filter these using categories - trouble is i use the category 'featured' across all 3 areas so it is relating blog posts just because they share 'featured' category

    is there any way I can say 'ignore the 'featured' category' when scoring?

    many thanks again

    1. avatar
      wrote this comment on

      Hi Dean, sure, it's documented in the readme.txt. There are various scoring options you can disable/enable.

      1. avatar
        wrote this comment on

        You can do this for just one specific category? by category ID?

        I thought you could only add/reduce weighting for all categories?

      2. avatar
        wrote this comment on

        thanks for your replies

        ideally I'd like it to ignore for example Category ID6 for scoring but not penalise any post if it has that category.

        my test site is here if you want to see [edit: 404]

        anything that is 'Featured' category is what gets sent to the slideshow - which build a 'false' relationship

  31. avatar
    wrote this comment on

    "There is no fulltext index for wp_posts.post_content
    There is no fulltext index for wp_posts.post_title"

    How I can solve this error?

  32. avatar
    wrote this comment on

    Greetings Nicolas!

    This is a great plugin. I have read this thread carefully and verified, that I am running PHP5 with MySQL 5.0.32. All tables are MyISAM. The plugin is creating FULLTEXT indexes called post_content_index and post_title_index for the post_content and post_title fields. I have even dropped and created the indexes by hand and used the code you suggested above. I received no errors in that process. My host will not be updating our MySQL version (grid based) for several months so I am stuck with it for now.

    Unfortunately, I still receive the below error. Do you have any other thoughts?

    There is no fulltext index for wp_posts.post_content
    There is no fulltext index for wp_posts.post_title

    Thank you very much!

    Mike

    1. avatar
      wrote this comment on

      Hm, that's odd. If the indexes exist maybe my code to detect them is buggy. Did you try to output related posts on the frontend? I'm not sure if the plugin would try to display them even without indexes detected.

      What you can try is to add a <code>return true;</code> on line 223 of better-related.php to bypass the index detection. Please do tell me if the plugin works then, as that would be a rather annoying bug :-|

      1. avatar
        wrote this comment on
        Same/similar issue here. When I inserted "return true;" on line 223 the plugin worked great.
      2. avatar
        wrote this comment on

        Nicolas,

        I was able to get this corrected. It was not a problem with you plugin but with my database. I asked my host to take a look at the MySQL server and they corrected or changed something. Thank you for your comments and a great plugin!

        Mike

      3. avatar
        wrote this comment on

        Glad to hear it works :-)

  33. avatar
    wrote this comment on
    Hi Nicolas,

    Your plugin is really perfect. It is no doubt the best among all the similar plugin.

    I have encountered a problem that I am unable to resolve hoping you can kindly help on it.

    My blog can set the post to be automatically outdated for a period of time and the updated post will not be shown publicly.

    However the related post plugin can find the related OUTDATED post and show up the OUTDATED post title.

    How can I exclude those OUTDATED post from the related post result? Or do not show post more that a period of time, say 30 days?

    Many Thanks in advance.
    1. avatar
      wrote this comment on
      The readme.txt has examples on how to build custom loops. That should make it easy to exclude some posts.
      1. avatar
        wrote this comment on
        In the scorer.php

        Line 300, I change to:

        WHERE ( post_status='publish')

        from:

        WHERE ( post_status='publish' OR post_status = 'private' )

        And Line 463 I change to:

        AND ({$prefix}posts.post_status = 'publish')

        from:

        AND ({$prefix}posts.post_status = 'publish' OR {$prefix}posts.post_status = 'private')

        But it is still showing the private posts. What should I do?

        MANY THANKS!
        1. avatar
          wrote this comment on
          Did you clear the score cache? You can do it on the options page.
          1. avatar
            wrote this comment on
            Hi,

            I do you clear the score cache ?

            Indeed I still can see private posts...
  34. avatar
    wrote this comment on
    To follow up my previous comment.

    My question is how to exclude the "Privately Published" post?

    THANKS!
  35. avatar
    wrote this comment on
    I really love Better Related Posts. It pulls in all the content I want it to seamlessly. But there is another related posts plugin that I am tempted to use in place of Better Related Posts: Related Post Thumbnails! I love the plugin because of the thumbnails feature, but it just doesn't pull in "related" posts like Better Related Posts does. Think you could add optional thumbnail functionality? I really like how well Better Related Posts, but it just isn't "pretty" enough. Great job on it though; it's the best one I've found!

    Thanks,

    Kallan
    1. avatar
      wrote this comment on
      Hello Kalan. No, I prefer to keep this plugin lean. However, adding thumbnails to the list display is very easy and there's even an example in the readme.txt on how to do it.
  36. avatar
    wrote this comment on
    hi nicolas

    I'm making heavy use of custom meta fields in my site - and importing data into them from a Filemaker database

    When I look at my database tables every custom field seems to have a duplicate - so I end up with one populated by filmmaker and one empty

    Can i just check whether your plugin needs there to be duplicates of custom fields to work? Would your plugin duplicare custom field data in the wordpress database?

    any help greatly appreciated
  37. avatar
    wrote this comment on
    Hi Dean. This plugin uses the post meta to store relatedness scores. It stores all of them in one meta field, so it doesn't duplicate fields. The default field name would be something like better-related.
  38. avatar
    wrote this comment on
    Thanks for the plugin- if I can get it working, it will be the only one that can handle custom post types and related posts.

    But I cant get it to work with custom post types.

    It is displaying related content just fine with related pages and posts, but it is not displaying any related content from my custom post type 'events'. I have read the readme 20 times and all forums/comments. Can you help?
    1. avatar
      wrote this comment on
      Check the plugin options page and select your custom post types? That should do.
  39. avatar
    wrote this comment on
    Hello,

    When I try to activate the plugin, I'm back with "plugin is enabled"but it remains off the list and I found nowhere menu for the parameter, and front "Call to undefined function"

    ???

    Thank you for your help.

    1. avatar
      wrote this comment on
      Can you post the complete error? Are you maybe running an outdated WordPress version or PHP4?
  40. avatar
    wrote this comment on
    Hi Nicolas,

    Is it also possible to show your plugin as a widget?
    1. avatar
      wrote this comment on
      Hm, I haven't included a widget. You could <a href="http://codex.wordpress.org/Widgets_API">give it a try yourself</a>, writing a simple widget isn't too hard.

      You might have to save the post ID into a variable and use it with the <tt>the_related_get_scores()</tt> call, I'm not sure if global $post is still set after the loop.
  41. avatar
    wrote this comment on
    hi again Nicholas

    I asked this above but was not sure I was clear on on my question"

    Can you remove one specific category from influencing the score?

    I have lots of posts that use the category 'Featured' to send them to a home page slideshow but they are not related. The plugin obviously thinks they are.

    So - is there any way to tell the plugin to ignore JUST the 'Featured' category for scoring purposes?

    Hope you can help

    Dean

    1. avatar
      wrote this comment on
      Hmmm, I don't think this is possible, but I'd have to check the source code again. Pretty busy at the moment though, sorry about the late reply.
  42. avatar
    wrote this comment on
    Hi, I've read through all the comments here and the readme.txt but I can't seem to get this to work quite right.

    When I use the plugin to automatically embed the related posts, it works fine but I can't get the manual insert with a custom loop to work.

    I need to call the plugin only on the single post pages for my 'work' custom post type, and want it to pull custom posts from the 'artists' custom taxonomy. It works find when I use the settings in the admin panel but with - as far as I can gather - the same settings manually coded in it's only calling regular posts that don't share the 'artists' taxonomy.

    This is the code I'm using: http://pastebin.com/HAJw1c5M
    1. avatar
      wrote this comment on
      You are passing $args to WP_Query that you should pass to the_related_get_scores(). WP_Query doesn't know what to do with any of these.

      You need the_related_get_scores( get_the_id(), $args ), and to pass the result of that as 'post__in' parameter to WP_Query.
  43. avatar
    wrote this comment on
    Hi Nicholas,
    I've read the readme.txt. But I do not find how to exclude certain category or tags of my post.
    Example: i wanna hide related post from category "video".
    Can i ? What code should i write on the single.php ?
    Thanks. I'm sorry i can't speak english well.
    Hehehe..
    1. avatar
      wrote this comment on
      I think you can do that by just passing the necessary parameters to the WP_Query (if you build a custom loop like described in the readme.txt)
      1. avatar
        wrote this comment on
        I really newbies Mr. Nicolas. I'm not a Superp Programmer like you. I still dont understant what u describe in readme.txt. Can u write that code here. So i can just copy and paste it to my single.php ?
        GOD BLESS YOU.
  44. avatar
    wrote this comment on
    This plugin shows the best post selection among other related posts plugins so I stoped on it. But is there any way to force one post alway to appear for another post i.e. to set some custom field like related_post_1 = URL ?

    If there is, I could not find it, if not, I think it would be a great idea to add it.

    Any way, here's your plugin in action: http://www.bielousov.com/2011/toronto-lollipop/
    1. avatar
      wrote this comment on
      There's no built-in way to do this at the moment, no. If you know a little about wp coding you could probably just use a custom field and use that for the custom loop you build.
  45. avatar
    wrote this comment on
    I've got two post types set up and each has the same set of custom taxonomy.

    For example one post type is called 'Events' and another called 'Training' and then both post types have the same set of taxonomy. I'm looking for a way to cross reference posts.

    With this plugin is it possible to get the taxonomy from the current post, but then display related posts from the other post type with that same taxonomy name?

    Thanks
    1. avatar
      wrote this comment on
      Yeah. In fact that's the default behavior. If you select taxonomies to include in the relatedness score each term of every taxonomy is checked against every term from all other selected taxonomies.

      It's actually a bug, but a small and sometimes useful one so I haven't fixed it yet. I'll probably keep this as the default behavior in the future as well as some people might depend on it.
  46. avatar
    wrote this comment on
    Great Plugin! Just a small bugfix

    I was getting a PHP warning notice: Undefined variable: r in .../better-related/inc/frontend.php on line 169
    when there were no related posts found.

    FIX:
    if (isset($r)) return $r;

    1. avatar
      wrote this comment on
      Thanks, I'll keep this in mind when I work on the next release.
  47. avatar
    wrote this comment on
    Just noticed that to display just 5 related posts on a blog, your plugin adds 17 SQL queries on a single post page. Isn't that too much? If you can optimize them to a more manageable number then it would be great.
    1. avatar
      wrote this comment on
      The plugin should cache all related posts it finds until you publish a new post. The number of queries also depends on the scoring methods you use.

      17 queries itself isn't a problem at all. It can be a problem if those 17 queries have to go through a post table with a million posts though. That's why there's a query limit and incremental scoring.
  48. avatar
    wrote this comment on
    I can't seem to activate the plugin on Wordpress 3.2.1 with all other plugins disabled and with Twentyeleven theme. Any chance of making it compatible?
    1. avatar
      wrote this comment on
      Do you get some error message?
      1. avatar
        wrote this comment on
        Wordpress produces no error messages - all I get is a message saying it is activated but when I look at the plugins list Better Related Posts plugin still has the activate option available.
        1. avatar
          wrote this comment on
          Hm, thanks, I'll have to test this.
  49. avatar
    wrote this comment on
    Great code! I noticed in the files you disabled attachments as an option. I'm using another plugin (http://wordpress.org/extend/plugins/media-tags/) that uses custom taxonomies assigned to attachments. I hope someday you decide the plugin will support attachment relations. It would be great to have related images!
    1. avatar
      wrote this comment on
      That's a great idea! Unfortunately I'm not using wordpress for my own sites any more, so there's only the small chance a client would need this feature and allow me to release the upgrade.
  50. avatar
    wrote this comment on
    Hello,
    first of all: great plugin.
    Is there a way to display an excerpt following the related links?
    It would be great if it is possible to show the normal excerpt of the post (or a certain count of words of the content section)...
    Best regards,
    Oliver
    1. avatar
      wrote this comment on
      Yes this is possible, but you'll need to write a few lines of PHP code. It's documented in the readme.
  51. avatar
    wrote this comment on
    Hi Nicolas,

    Does this work with WP MultiSite Network.

    Is it compatible across network?

    Thank You!
    1. avatar
      wrote this comment on
      It depends on what you mean? Sure, it works on blogs inside a network. However, it doesn't give you related posts from other blogs in the network.
  52. avatar
    wrote this comment on
    Hi Nicolas,

    I'm using the custom code from the readme text (first example), but I can't get it to display the related post titles. It keeps saying 'no posts found'.
    Though in the $posts array all the post id's are ok (eg
    <?php Array ( [0] => 238 [1] => 428 [2] => 579 [3] => 606 [4] => 486 );?>



    <?php the_related();?>

    works fine, but I would like to use the custom code to display some metabox fields from a custom post type.

    Am I missing something? I'm not a coder, could you help me out a little bit?
    Thanks!
    Britt
    1. avatar
      wrote this comment on
      Hrm, can you paste your whole code here or on a pastebin site? Not really sure what's going on here.
  53. avatar
    wrote this comment on
    Hi Nicolas, great plugin! Good work :)
    Got one question though; is it possible to show only related posts from the same custom post type? I only want to use the post_tag for relevance, but if you haven't filled in any tags somehow they show up on other custom post type posts...
    Thanks!
    1. avatar
      wrote this comment on
      You can use the usept parameter for this. Please see the readme.txt
      1. avatar
        wrote this comment on
        Yup, that did the trick! When using multiple configurations they will all use the variables set in the global plugin settings if you don't specify them right? Thanks again!
  54. avatar
    wrote this comment on
    Hi Nicolas,

    First, I would say thank you for making a great plugin. It solved a lot of my problems searching for related post plugin to display related videos of my site in which I realized it's using custom taxonomy. Other related post plugin doesn't work until I found yours.

    I just wonder on how to add a thumbnails to the results. I can only find the title link. I read your readme.txt but I don't know where i should start. I see this line in readme.txt:

    if ( has_post_thumbnail() ) {
    the_post_thumbnail( 'thumb' );
    }
    echo '<br>';

    I don't know if this is the line I am looking for and if it is,I don't know where to insert it, what file should I edit. Hope you can help me with this little problem. You are a great talented person.

    Thanks.
    1. avatar
      wrote this comment on
      Yes, this is the code to add the thumbnail. You just add it where you want to thumbnail to appear inside your loop. See http://codex.wordpress.org/The_Loop for an introduction.
  55. avatar
    wrote this comment on
    hi, the plugin works great for me but I have one little problem in admin area.. I've entered at "Related posts title" the following: ~span style="background-color: #FFDECF;"~Related:~/span~

    After I saved changes, it appeared as '~span style=' in text area and 'Related:" size="60" /~' outside the editing area. I don't really need to change it right now but for the future, where should I look for editing this?
    1. avatar
      wrote this comment on
      Hm, not sure what you mean, but you should probably use your normal css stylesheet and add rules there.
      1. avatar
        wrote this comment on
        hey, thank you for your answer. Let me make it easier to understand: how can I edit the text that is underlined with red in the following picture: http://img197.imageshack.us/img197/2434/betterrelatedcontent.png
        1. avatar
          wrote this comment on
          Oh, this might look like a bug. I'll look into a fix. I should have a little time soon.
  56. avatar
    wrote this comment on
    Hi, yep i agree with everyones sentiment that this is great plugin, so thanks, but i seem to be having trouble getting it to work, good chance im overlooking something so was hoping you could offer some insight.

    When i have the plugin enabled to show up in default wp posts it works fine.

    But when i use a cpt with a default content editor and custom fields its returning 'No related content found' in that post type or for any other post type. ive tried with both the admin options and the manual options in the readme. I get the same result when i run the_related_analyze() too. Id does however return results for the default wp posts when i use the 'custom loop of related posts' example in a ctp.

    At a bit of lose and would be if you could offer some advise. Much Appreciated
    1. avatar
      wrote this comment on
      the_related_analyze() should show a lot of different scores IIRC. Don't you get any related value anywhere? Maybe it's a caching issue, there should be some reset scores option on the admin page (or change the storage key).
      1. avatar
        wrote this comment on
        Yeah i only get 'No related content found.' on all the listed items when i call the_related_analyze(). Ive started with a fresh db, created a new ctp and added 2 new posts with related titles and content but still nothing is returned and i get 'No related content found'. Not sure what else to look for?? Thanks
        1. avatar
          wrote this comment on
          Hmmm, your cpt uses the normal editor, doesn't it. Maybe your posts are just so different that they aren't related to each other at all?
  57. avatar
    wrote this comment on
    Hi!
    The Plugin is very nice and used to work for me, but I recently changed my theme and since then the releated posts only show up in the single-post-view. Is there some solution?

    Thanks for all :-)
    Miri
    1. avatar
      wrote this comment on
      I think I add a filter on the_content to add the related posts. Maybe your theme is a little odd and doesn't use that default template tag. In the readme.txt is a method to place the related posts manually, you could try that.
  58. avatar
    wrote this comment on
    this is really cool plugin...how can i edit the css for it to even show thumbnails for post too...thank you
    1. avatar
      wrote this comment on
      IIRC the readme.txt has an example of a custom loop.
  59. avatar
    wrote this comment on
    Hi there,

    I'm getting some errors at the top of my related posts all of a sudden:

    Warning: array_keys() [function.array-keys]: The first argument should be an array in /path-to/single.php on line 69

    Warning: array_slice() expects parameter 1 to be array, null given in /path-to/single.php on line 69

    Warning: array_search() [function.array-search]: Wrong datatype for second argument in /path-to/single.php on line 79

    etc.
    But only on 1 certain post? In single.php line 69 looks like this:


    <?php
    $scores = the_related_get_scores(get_the_ID(), array( // Line 61
    'usept' => array(
    'post' => true
    ),
    'usetax' => array(
    'post_tag' => true
    )
    ));
    $posts = array_slice( array_keys( $scores ), 0, 5 ); // Line 69
    $args = array(
    'suppress_filters' => true,
    'post__in' => $posts,
    'posts_per_page' => 5,
    'caller_get_posts' => 1
    );
    $my_query = new WP_Query( $args );
    function orderby( $a, $b ) {
    global $posts;
    $apos = array_search( $a->ID, $posts ); // Line 79
    $bpos = array_search( $b->ID, $posts );
    return ( $apos < $bpos ) ? -1 : 1;
    }
    usort( $my_query->posts, "orderby" );
    ?>



    Any ideas on what might be causing the problems?
    The particular post on which the problem occurs has some <object> and <iframe> tags in it.

    Thanks for your help!
    1. avatar
      wrote this comment on
      I think that the the_related_get_scores() function can return false or something that's not an array when no related posts are found. So you should check if you get an array from it.
      1. avatar
        wrote this comment on
        I do get an array from the_relatedget_scores(), because there are related posts underneath these warnings. I did som tests and it appears these warnings only occur when there are embed codes like <embed> and <iframe> in the post like soundcloud for example.

        I made a post on the wordpress forums for more detailed information:
        http://wordpress.org/support/topic/plugin-better-related-posts-embedcode-post-causing-warning-array_keys

        It's definetely plugin related because when I disable the plugin, or remove the php code, the warnings dissapear too.

        Any ideas?
        1. avatar
          wrote this comment on
          You should probably start by debugging every step of the code, using print_r(), var_dump() etc.
          1. avatar
            wrote this comment on
            You mean my code in the single.php template or your plugin code?
            Because
            print_r($scores)

            returns nothing and
            var_dump($scores)

            returns 'NULL'.

            Weird, it only happens when the post content has some embed codes...
            1. avatar
              wrote this comment on
              Am I really the only one experiencing this problem?
              1. avatar
                wrote this comment on
                It's an odd problem for sure. Sorry I don't have the time to look into it right now.
  60. avatar
    wrote this comment on
    Any plans to change this plugin to use InnoDB?
    1. avatar
      wrote this comment on
      Not likely, unless InnoDB gets support for mysql relatedness score for fulltexts
  61. avatar
    wrote this comment on
    Nice plugin ! It would be better if you include a widget...
    Thanks
    1. avatar
      wrote this comment on
      Feel free to submit a patch. Reminds me.. I have a few to review..
  62. avatar
    wrote this comment on
    i am use your plugin
    when i am post my hand i am see related post like it
    http://fonec.info/?p=4055


    post posts which auto post by plugin
    FeedWordPress

    simple and flexible Atom/RSS syndication for WordPress


    related post not see like in links
    http://fonec.info/?p=4035
    http://fonec.info/?p=3590

    hope you understanding me
    and i am wait your help
    www.fonec.info
    1. avatar
      wrote this comment on
      Hmmmm... no I don't really understand what you mean.
  63. avatar
    wrote this comment on
    posts come from using plugin FeedWordPress in that case not get realated posts
    link post in link
    http://fonec.info/?p=6706


    but when post from site by my self get reated posts
    like that post
    http://fonec.info/?p=6647

    hope understanding me
    1. avatar
      wrote this comment on
      Hm. No idea. Maybe the posts you feed into wp aren't related at all to your pervious content. I can't think of anything else right now as the plugin can search for related posts for every request on the frontend.
  64. avatar
    wrote this comment on
    My problem is that i want to show my custom post type of portfolio...but somehow i am not able to get it work...i want to show thumbnails of the related portfolio item on single post page...you can check out my website http://www.indezoo.com for better understanding!!!
    1. avatar
      wrote this comment on
      Not sure what your question is. IIRC the readme has an example with thumbnails. If you get no related posts check the analyze function.
  65. avatar
    wrote this comment on
    Great Plugin, the only one that work very well.

    One question. I use the tag 'the_related_for_string' and set the limit to 9 post but the result is only 5 post. Any Ideas how to set the limit for this tag ?

    Thank you so much.
    1. avatar
      wrote this comment on
      Hi. You can pass the number of posts to return as second parameter. the_related_for_string('foo', 9). You can also pass a complete config as third parameter. Looks like this isn't in the readme yet.
  66. avatar
    wrote this comment on
    I've been trying to exclude private posts, pages and CPTs and have made edits to lines 300 and 463 as you suggested above and exactly as detailed by Chanery (on March 27, 2011 above). However I too was still seeing private posts in my results. Then I read about clearing the cache, but couldn't really figure out what you meant, until I found a setting in the options page for the plugin called "Data storage engine" (Post Meta or Transient). So I switched it to Transient and it fixed it, kind of, because now the private posts were eliminated from my results, however, when I change the setting back to "Post Meta" which sounds like the better option for the long term, all the private posts return.

    What am I missing? and how can I clear the cache? is this something i must manually do in the db table via phpMyAdmin? If so, I'm a bit clueless when it comes to editing DB's.

    Thanks, and I love your plugin. When are we going to see some updates from all the great ideas posted above?
  67. avatar
    wrote this comment on
    Isn't there something like a cache key you can configure? Or storage key maybe? Can't check at the moment, but changing that should clear the cache.

    I shall put the code on github so that everybody can contribute patches. I'll try to do that in the new year.
  68. avatar
    wrote this comment on
    Hi Nicolas, I can't find any information about using your related content plugin with a wordpress cache plugin, any advice? Better one? Not affected by external caching system?
    Thanks a lot.
    1. avatar
      wrote this comment on
      I don't think that using a cache plugin will affect this plugin in any way with the default configuration. Probably if you do incremental scoring.
  69. avatar
    wrote this comment on
    Hey Nicolas ,

    This plugin is really awesome , thanks for your effort .
    I Have a small question , is there any code I can put in a certain post I don't want Related Posts to appear ?? Plus excluding this post from appearing on the related posts menu on other posts .

    Waiting for your reply :) .
    Thanks in Advance .
    1. avatar
      wrote this comment on
      Hi, you probably want to read the codex page on conditional tags? http://codex.wordpress.org/Conditional_Tags
  70. avatar
    wrote this comment on
    I switched to CloudFlare for performance reasons, and I think this is causing your plugin to no longer work. Do you know if that would affect your plugin from displaying posts? I keep getting "No related posts found" on all my posts when it would normally return many.
    1. avatar
      wrote this comment on
      Hi Kyle, I'm afraid I don't know what cloudflare is or how it could affect my plugin.
      1. avatar
        wrote this comment on
        I have the same problem getting "No related posts found" on all my posts,do you give me some suggestion?
  71. avatar
    wrote this comment on
    Awesome plugin!! :)

    Any idea why it's showing a blank <li> at the bottom of this page in the related articles section:

    http://www.partybuilders.com/ad-category/party-planners/

    I think it has something to do with the code from here, because I changed it from <ul> to <li> to see the dots in front. Any ideas?

    if ( !function_exists( 'the_related_for_string' ) ) {
    function the_related_for_string( $string, $maxresults = 5, $config = null ) {
    $scores = get_the_related_for_string( $string, $config );
    $listed = 0;
    foreach( $scores as $id => $score ) {
    if ( $listed >= $maxresults )
    break;
    if ( $score == 0 )
    break;
    $listed++;
    $link = get_permalink( $id );
    $title = get_the_title( $id );
    $post_type = get_post_type( $id );
    if ( !$title ) {
    $title = __(
    'This entry has no title',
    'better-related'
    );
    }
    $description = $title;
    $related .= "<li> <a href=\"$link\" title=\"Permanent link to $description\">$title</a></li>\n";
    }
    if ( @$related )
    echo '<ul>' . $related . '</ul>';
    elseif ( $relatednone = $config['relatednone'] )
    echo $relatednone;
    }
    }

    1. avatar
      wrote this comment on
      Thanks! Well... <li> is not the correct tag. Opera has a great page about HTML lists:

      http://dev.opera.com/articles/view/16-html-lists/

      You should also validate your HTML from time to time, see

      http://validator.w3.org/check?uri-charset=%28detect+automatically%29&uri-doctype=%28detect+automatically%29&ss=true&uri=http%3A%2F%2Fwww.partybuilders.com%2Fad-category%2Fparty-planners%2F
      1. avatar
        wrote this comment on
        Thanks responding Nicolas.

        I switched it back to <ul>, but it just lists the content without putting the bullet. Any idea why it is doing that?

        http://www.partybuilders.com/ad-category/party-planners/

        Thanks,
        John
        1. avatar
          wrote this comment on
          Hi John, well that's a CSS issue. You should probably ask your theme developer.
  72. avatar
    wrote this comment on
    I've downloaded and 'activated' your plug-in, it sounds great but it's not showing up on my blog. I've read through the comments above but I'm pretty new to blogging, no knowledge whatsoever of programming etc and most of it is greek to me. Any suggestions as to what else I need to do? Or can you point me to a really, really explanation of how I get it up and running?
    1. avatar
      wrote this comment on
      You should have a look at the README file or http://wordpress.org/extend/plugins/better-related/installation/
  73. avatar
    wrote this comment on
    Hey Nicolas, I created an awesome looking related posts loop based on your read me instructions that even vary by browser/device width but with the custom loop active, it somehow screws up my comments. I don't know precisely what it's doing, but if you leave a comment on any given post, it's actually assigning the comment to a totally different post (probably a "related" one). It displays the comment on the post where you posted it, but in the database, the comment is actually assigned to the second post. Even when you post the comment, the page redirects to the new post, not the post where you left the comment. Very bizarre. Anyway, I tracked it back to the use of my custom loop. I cannot understand how this could affect comments, OTHER THAN, the query for the custom loop must be messing with the post ID of the current post?

    Here's my custom loop code: http://pastebin.com/2kYYN1jx

    Any help or insights into why this is happening would be much appreciated.
    1. avatar
      wrote this comment on
      Hi Suzanne, this sounds similar to the comments issue I mention on

      http://www.nicolaskuttler.com/post/wordpress-loop-inside-a-loop/

      Try using wp_reset_postdata() after your custom loop.
      1. avatar
        wrote this comment on
        SUCCESS! That fixed the issue. Thanks so much for building such a great plugin and helping everyone so patiently as you do. I wrote a post featuring the plugin and I share the code I used for my custom loop. You'll also see my related posts in action. Some posts have images, others do not. Make your browser window wider and smaller too to see how they react to varying widths ;) http://ahjira.com/plugins/
        1. avatar
          wrote this comment on
          Great! I like the fluid layout. Will see that I add the comment info to the readme, thanks!
  74. avatar
    wrote this comment on
    Hi!

    Great plugin. How do I change its position? In my blog posts (see e.g. http://bit.ly/INkdQj) the related posts appear at the end of the post text, but I would like it to appear after the bookmarks and the text in the blue dotted border.

    I'd also like to display the post thumbnails, likein the blog homepage.

    Thank you!
    1. avatar
      wrote this comment on
      It seems like you already sorted the thumbnails out? As for positioning it depends on how you generate the list, you just put your custom loop wherever you need it.
  75. avatar
    wrote this comment on
    Nicolas, is there any way possible to provide a step by step instructions on how to display the Thumbnails of the custom posts? I'm a beginner but I can find my way around between the core templates and functions, but I cant for the life of me get the proper steps to have the thumbnails show up :( I tried going through the readme.txt file, I see the code but no idea where to place it or how to declare it :(
    1. avatar
      wrote this comment on
      Hm, you need at least a little experience with wp coding to do this. You put the code wherever you want the related comments to appear. Not really sure what you mean by declaring though. The wp codex has a lot of docs for theme building etc.
  76. avatar
    wrote this comment on
    I realized I should've put the code tags around that last comment. Here we go:

    <?php
    global $posts;
    $posts = array();
    $home_query = new WP_Query( array(
    'post__in' => $posts,
    'posts_per_page' => 10,
    'post_type' => 'videos'
    ));
    function home_orderby( $a, $b ) {
    global $posts;
    $apos = array_search( $a->ID, $posts );
    $bpos = array_search( $b->ID, $posts );
    return ( $apos < $bpos ) ? -1 : 1;
    }
    usort( $home_query->posts, "home_orderby" );
    while ($home_query->have_posts()) : $home_query->the_post();
    ?>
    <div <?php post_class() ?> id="page-<?php the_ID(); ?>">
    <a href="<?php the_permalink(); ?>"><div class="videotitles1"><?php the_title();?></div>
    <?php echo get_the_post_thumbnail($id, array(120,120) ); ?><div class="videoauthor">by&nbsp;<?php the_author(); ?></div><div class="videolength"> <?php $videolength = get_post_meta($post->ID,'videolength',true);
    echo "$videolength";?></div></a>
    </div>
    <?php endwhile; ?>

    1. avatar
      wrote this comment on
      Oh snap, I deleted your other comment, you probably had a question?
      1. avatar
        wrote this comment on
        Yup. I'm trying to get that query to sort by most related posts, but can only get it to sort by the time posted.
  77. avatar
    wrote this comment on
    Dear Nicolas,

    Great plugin. Is there any chance to add a post meta cleanup function as you mentioned in this forum threed? goo.gl/ub2uU
    It would be a really usefull feature.

    Thank you!

  78. avatar
    wrote this comment on
    For custom post types, I ended with "No related content found", too.
    I am trying to analyze why this is still happening.
    1. avatar
      wrote this comment on
      Use the the_related_analyze() method described in the readme.
  79. avatar
    wrote this comment on
    Hi Nicolas - this seems like just the plugin I've been looking for, but I could use some configuration advice. I've searched here and there for an explanation of just what incremental scoring is, but other than answers to comments here, there's not much clue. I have about 2000 sometimes-long-winded blog episodes, my own server (macminicolo rocks), yet I have no idea whether to turn on incremental scoring, or what effect the query limits actually have.

    Have I missed the part in the docs where you explain that stuff?
    1. avatar
      wrote this comment on
      Hi Jerry, you don't need incremental scoring, it's intended for sites with hundreds of thousands of posts.
  80. avatar
    wrote this comment on
    Thanks for the plugin, it running well.
    But I need to remove base urls on the links, how can I do that ?
    ps. for example href=http://www.example.com/bla-bla-bla/ to href=/bla-bla-bla/
    1. avatar
      wrote this comment on
      Why would you need to do that? Anyway, use some filter on get_permalink or whatever it is. See the filter reference.
  81. avatar
    wrote this comment on
    After Wordpress 3.5 update I have encountered this problem and had to disable this wonderful plug-in:

    "Warning: Missing argument 2 for wpdb::prepare(), called in /home/sitename/public_html/wp-content/plugins/better-related/inc/scorer.php on line 329 and defined in /home/sitename/public_html/wp-includes/wp-db.php on line 990"

    1. avatar
      wrote this comment on
      I have just uploaded 0.4.3.4 which removes the warnings. The warning isn't an error by the way and you should disable warnings on public servers. Enjoy the first update in a looooong time :-)
  82. avatar
    wrote this comment on
    Upgrade to Wordpress 3.5 and now receive the following error:

    Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/better-related/inc/scorer.php on line 474 and defined in /wp-includes/wp-db.php on line 990

    This can be fixed as outlined here:

    http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/

    Thank you.
    1. avatar
      wrote this comment on
      Hi,
      for Wordpress 3.5 I receive the following error:

      Warning: Missing argument 2 for wpdb::prepare() etc...
  83. avatar
    wrote this comment on
    Howdy would you mind stating which blog platform
    you're using? I'm going to start my own blog in the near future but
    I'm having a difficult time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I'm looking for
    something completely unique. P.S Sorry for getting off-topic but I
    had to ask!
    1. avatar
      wrote this comment on
      I wrote this site myself using the excellent Django framework, see https://www.djangoproject.com/
  84. avatar
    wrote this comment on
    Hi, I'm also getting the "There is no fulltext index" issue.

    My tables are all InnoDB by default. I don't feel good about changing that, although I don't know enough about MySQL to substantiate that feeling.

    Any update on this issue?

    Thanks for all your hard work.

    Michael.
    1. avatar
      wrote this comment on
      Hi Michael, sorry, the plugin can't work with InnoDB. This is a flaw in the core design. I won't update the plugin any more as I have stopped using wordpress myself. Maybe if somebody offers a contract, but it's unlikely I would even do it then.
  85. avatar
    wrote this comment on
    I like this plugin! And I have translated it to chinese. do you plan to add it to the new version?
  86. avatar
    wrote this comment on
    Convert the table wp_posts to MyISAM and replace two lines in better-related.php with the ones below (line 224,225)
    224 $query = "SELECT COUNT(*) FROM information_schema.STATISTICS WHERE TABLE_NAME='{$wpdb->prefix}posts' AND COLUMN_NAME='%s' AND INDEX_TYPE='FULLTEXT';";
    225 $indexes = $wpdb->get_var( $wpdb->prepare( $query, $column ) );


    Then deactivate the plugin and reactivate.