Support » Plugin: Contextual Related Posts » [Plugin: Contextual Related Posts] Nav Menu Issue

  • Been using a related post plugin for years (think it’s the first one ever made, authors Alexander Malov & Mike Lu, domain it was from long dead) and today realised if you create a custom nav menu and change the title of the post links the related post plugin will use the new title to generate a link to a non existent post (the excerpt is from the right post mind you, so it’s the anchor text and URL).

    I’m running with SEO friendly permalinks, I assume this wouldn’t be an issue with the default dynamic URLs.

    You can see an example at see the first related post entry where I’d added a link to this page to a nav menu and shortened the title to Comment Titles.

    Been looking for a new related post plugin and the Contextual Related Posts Plugin this one has the same bug.

    To test this, make a custom nav menu, add a posts to it and rename the title. Go to that post and you’ll find a link like I showed above: you’ll find link to the post with the nav menu link anchor text and the wrong URL.

    Guessing no ones noticed this behaviour, any thoughts on a fix?


Viewing 3 replies - 1 through 3 (of 3 total)
  • Fixed it,

    Here’s the changes I made

    if ((is_int($post->ID))&&($stuff != '')) {
    $sql = "SELECT DISTINCT ID,post_title,post_date,post_content,post_type,"
    #        $sql = "SELECT DISTINCT ID,post_title,post_date,post_content,"
            . "MATCH(post_title,post_content) AGAINST ('".$stuff."') AS score "
            . "FROM ".$wpdb->posts." WHERE "
            . "MATCH (post_title,post_content) AGAINST ('".$stuff."') "
            . "AND post_date <= '".$now."' "
            . "AND post_status = 'publish' "
    . "AND post_type != 'nav_menu_item' "
    . "AND post_type != 'revision' "
            . "AND id != ".$post->ID." ";
            if ($crp_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
            $sql .= "ORDER BY score DESC ";

    Changes to contextual-related-posts.php

    Edit one line and add two new lines to check a post isn’t post_type nav_menu_item, also added revison as well as they have a different ID and assume users who use the default dynamic URLs will get links to the wrong dynamic URL.


    Plugin Author Ajay


    Thanks David, I’ll implement this one

    No problem.

    Not particularly good with optimising database queries, but you might be able to use a better implementation and reduce the number of database queries by not checking the entries with post_type as nav_menu_item and revision.

    When I went searching for the cause of the issue I was surprised to find how WordPress generates the nav menu items, it’s a copy of the entire post entry with a different post title! This is bound to generate problems with other plugins that assume everything in that table is a post.

    Feature suggestion 🙂 Just started testing with your plugin, upgrading from the very old (and very good) related post plugin from Alexander Malov & Mike Lu (which needed a similar fix). In my current setups I don’t use lists for the output, put them in a paragraph with a header surrounding the link.

    h4 link to post /h4 P excerpt…. /p

    See the link I added to the first post above for example.

    Although you can surround the entire link with your plugin you can’t style the anchor text of the link with a header. I realise I could add styling via CSS, but I’m using the header code for SEO reasons: if a related posts plugin grabs relevant posts, the anchor text of those posts are likely going to include relevant keywords and by giving them a low level header (h4, h5, possibly h3 if you don’t add h3 to your posts) you potentially add optimisation for long tail related SERPs (I’ve been doing SEO way too long :-))


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Contextual Related Posts] Nav Menu Issue’ is closed to new replies.