• Resolved David Gard

    (@duck_boy)


    Hey all,

    I am generating links for a group of pages that have the same name as Categories using this method –

    if(is_page(69) || is_array($cat) && in_array(38, $cat)){
        $categories =  get_categories('child_of=38');
        $otherService1 = get_permalink(155);
        echo '<li><h2 class="staffList_bcg_active">Individuals</h2><ul>';
        if(!empty($categories)){
            foreach ($categories as $cat) {
                $post_id = $wpdb->get_var('SELECT post_name FROM wp_posts WHERE post_title="'.$cat->cat_name.'"');
                $allLinks = '<li><a href="http://www.dynedrewett.com/'.$post_id.'">'.$cat->cat_name.'</a></li>';
                echo $allLinks;
            }
        }
        echo '</ul></li>';
        echo '<li><h2 class="staffList_bcg_normal"><a href="'.$otherService1.'">Businesses</a></h2></li>';
    }

    While the list dispalys correctly and the mojority of the posts work, there is one that will not link correctly. It should create the link if ‘http://www.dynedrewett.com/disputes&#8217;, but it does not and instead creats ‘http://www.dynedrewett.com/297-revision-3&#8217;, with 297 being the Post_ID and revision 3 being the latest revision. I cannot think of what chould be causing this, so any help is appricated.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Should you be also checking in the query for post status (ie published)?

    Thread Starter David Gard

    (@duck_boy)

    These particular Posts should always be published, and the one in question indeed is – But I like the idea and will amend slightly to reflect that in the future when I work out how!

    I’m stumped – I have copied the Category name to the Post Name, so they are both the same. I have ensure the Post has the correct Categories selected (Services to Individuals and Disputes in this case) and the page does come up when manually typed in.

    I have also tried renaming the original Post and creating another, but the link is exactly the same even though it is now on revision 1.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Link to post not working correctly’ is closed to new replies.