• Hi everyone, i have a question about “Related Posts” plugin. My theme has a built in related posts, but it shows only posts from that specific category. I would like to change it to show related posts from the post title and not the category. I think i found the code in “single.php” but i dont know how to change it from category to post title. Here is how it looks like:

    <h3 class="blocktitle">Related Wallpapers</h3>
    <div class="row">
    <?php new_related_post($post);?>
    <div class="col-sm-12 col-md-12 col-lg-12 center advert"><a href="#">
    <?php echo get_theme_option('google_middle_ads');?>

    Example: A post with title “polar bear” shows related posts from “animals” category, i want to show similar “polar bears” posts and not any kind of animals.

    So please is it possible to change it? Or do i have to remove that built in plugin and install a new one? Thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m afraid category queries are a long way from title queries. The usual WP_Query class that is used does not even have an argument to search just titles. The closest thing is the default search query that searches not only titles, but content and excerpts. If you want to search just for words in the title and no where else, you will need a custom SQL query.

    If the related posts plugin offers hooks, it can possibly be modified to use such a query. Then you can still make use of its other features. Or you could create your own related post function and call it from your single.php template.

    The current function finds posts in the same category as the current post. Where will search criteria come from for a title search? The current post title? Category term names? If you use the current title, you should filter out insignificant words like “to, the, a, I, for, etc.” Should the results match all the remaining words or any one of them? There can be a lot of details to work through.

    Thread Starter dusanb17

    (@dusanb17)

    Thanks for your reply,
    i dont use words in post titles like “to, the, a” etc. I use post titles like “polar_bear”, dog_black”, etc. But can i just simply remove that built in plugin, and install a new plugin that supports post titles?

    • This reply was modified 8 years, 2 months ago by dusanb17.
    Thread Starter dusanb17

    (@dusanb17)

    Problem fixed, thanks WP community!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Related posts plugin change from category to post title’ is closed to new replies.