Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP passing requested post id and title in url but not showing id

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #146172
    Jochim
    Participant

    What’s the best way to achieve this? I’d like to have a forum with the post page displaying a url like example.com/forums/category/post-title. The problem is I want to look up the post in the database by it’s id instead of title because I’ve read that looking up by title is slow especially if you have a lot of posts.

    So to achieve this you would have to pass the title (or a slug of it) and the id, that’s what I currently have. I have my .htaccess set up to rewrite example.com/forums/category/post-id/post-title to example.com/forums/post.php?id=post-id. Now I just want to remove the id from the url, but I don’t know how… Any help please?

    Thanks.

    #147569
    zero_plus_plus
    Participant

    You would have to provide more details about the CMS you are using.

    As you have stated, ID based lookups are recommend, because:

    1) numeric comparisons are faster than string comparisons
    2) the ID field is almost certainly indexed in the database, which will make it much faster to lookup

    Your CMS almost certainly provides a way to get the post ID without extra work, by way of a function or global(ish) variable.

    For example, in WordPress you can retrieve the post ID by using a function, called get_the_ID. You could assign it as such:

    $id = get_the_ID();
    

    And then query the database to your liking.

    #147654
    zero_plus_plus
    Participant

    Not nice :(

    #147775
    zero_plus_plus
    Participant

    No, no, you misunderstood. It was directed at Jochim for posting the same thing twice, at two very different time intervals.

    #147927
    __
    Participant

    ah. Well, he may have had reason to. why I was asking.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.