The MU forums have moved to WordPress.org

How to check whether a post exists or not (5 posts)

  1. skcsknathan001
    Member
    Posted 12 years ago #

    I would like to check whether a post/ page exists or not before displaying the link to the post.

    You know you get "Sorry, no posts matched your criteria." when you click a link, which is not there.

    So I assume I have to somehow ping the post's address[?]. But how do I ping & get results when the link results in "Sorry, no posts matched your criteria." page? How do I figure whether its the correct page or not?

    basically how do I code in php :D

  2. andrea_r
    Moderator
    Posted 12 years ago #

    So you're trying to link to an entry before you know if it exists? I gotta ask why... ? :D

  3. skcsknathan001
    Member
    Posted 12 years ago #

    Oh. for languages encoded as Complex Scripts level-2 in Unicode, this problem comes up. People give pretty large name for the "Post slug" and when it saves, the URL actually gets cut off. So eventhough the post is saved and you can see it, you cannot link it since the URL is not right.

    Yes, its weird, I don't know too.

    So I would like to simply check before putting the link in my "WPMU Recent Posts" widget.

  4. Ovidiu
    Member
    Posted 12 years ago #

    this is not a direct reply to your question, but there is a very nice plugin here:http://pietersz.co.uk/2006/07/wordpress-slug-trimmer which cuts down long slugs (configurable)

  5. skcsknathan001
    Member
    Posted 12 years ago #

    Thanks Ovidiu for the link
    Even though that didn't fix my problem out of the box. I did some modification and kinda worked.

    The problem is that unlike English in Unicode, languages encoded as Complex Script Level-2 is kinda complecated.
    strlen($pos_slug) will give different value than
    strlen(urlencode($post_slug))
    Because of this when user enters post slug it saves the post but post slug gets cut off if URLENCODE exceeds 255. Since the Unicode encoding gets cutt of in the middle, now the URL is not understandable by the server!!!

    So I did a check for strlen(urlencode($post_slug)) and so only cut words at the <space>. So its not truncating a Unicode encoding. This works perfectly if strlen($pos_slug) > 190 [190 is the maximum character length I use as a cap]

    But now there is a problem is when strlen($pos_slug) < 190. But the strlen(urlencode($post_slug)) > 190 [hence exceeding 255 total sometimes]. This allows to save the post and people can link to the post. The problem comes when they update the post, the URL gets re-written and somehow the string gets truncated and hence server is not understanding the updated URL.
    Here is a link to my [edited] file

    slug-trimmer.txt
    [of course change the extention to .php]

About this Topic

  • Started 12 years ago by skcsknathan001
  • Latest reply from skcsknathan001