• Hi,
    I have a need to get the ugly url for a dynamic post from the permalink. In other words, I want to reverse the permalink encoding. Is there a function that can help me with this task?

    Alternatively, I want to rewrite a given “name” pretty permalink into “plain” permalink.

    The basic need is to reformat a “link” to a custom post. Doing so, allows me to force a “template page” under specific conditions I can check in code.
    Thanks,
    Carlos

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • I am confused have you tried changing the permalink settings under
    Settings → Permalinks ?

    If you have and your settings are not saving then there is probably a permissions error with your htaccess file. You will need to make sure your file has at least 644 permissions.

    Hope this helps, once you find a solution please tag the thread as resolved.

    Thread Starter cjsdfw

    (@cjsdfw)

    Hi Davood,

    Thanks for responding.

    I do not want to change the permalink setting, this will change it for all posts.

    Rather I have a need to determine the raw (plain permalink) from the current permalink: in other words reverse the rewrite for a specific link. In code and for specific conditions I want to set a page hyperlink to the “plain permalink” instead of the permalink specified in permalink settings.

    Thanks,
    Carlos

    Ah ha. So you only want to change the permalink structure for certain posts while leaving the rest using the structure that is set up in the settings I mentioned earlier? Correct?

    Moderator bcworkz

    (@bcworkz)

    You basically want the post ID right? If you can reliably extract the post slug from the permalink, you can do get_post(['name'=> $post_slug,]); The returned post object has the post ID along with all other post properties. Parsing any possible request URL gets pretty complicated. You need to use the rewrite rules to find a matching regexp to use to parse the permalink.

    If you are wanting the post ID in order to determine which template to use, for example in the “template_include” filter, you can get the ID of the currently queried object with get_queried_object_id(). This may not be a post ID. Use in conjunction with is_single() to be sure it is a post.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get Ungly URL from permalink URL’ is closed to new replies.