Support » Fixing WordPress » Convert permalinks to site ID, blog ID, type (e.g. 'post'), and type ID

  • Let’s say I have a permalink. Now I want to know how to CORRECTLY reverse engineer that permalink back into site ID, blog ID, type (e.g. ‘post’, ‘attachment’, etc.), and type ID. Basically, feed in a permalink and get back an array of useful information. I know get_permalink() generates a permalink, so what is the inverse function called?

Viewing 5 replies - 1 through 5 (of 5 total)
  • There’s isn’t an inverse function.

    You could get the URI using _SERVER and then split it down in to its componant parts using implode() – finally run some functions on the relevant array keys to get the info you want. Very long winded, probably not worth it, but possible for those who wish to persevere!

    It might help if you gave some details on why you need the various ids.

    @duck__boy – “probably not worth it”. I wouldn’t be asking if it wasn’t worth it.

    @esmi – I just knew someone would drop in and be completely unhelpful. Congratulations, you’re “that person”.

    I know WP pretty well as well as being an expert PHP developer, so I wouldn’t be asking if I didn’t need such functionality. I am more than capable of hacking something together, but what I want to know is what the “CORRECT” way of doing what I want to do? There’s always the hacky way and then there is right way.

    Since my post 35-ish minutes ago, I’ve scoured the WP codebase and have come across:

    url_to_postid() – requires switch_to_blog() and restore_current_blog() calls, but I’m used to doing that extensively already.

    get_blog_id_from_url() – which is rather misleading as to what it does.

    I’ve got a few ideas but this is hardly ideal.

    Edit: BTW, I already have the permalinks I’m looking to reverse engineer. So, the $_SERVER[] recommendation is equally useless.

    Edit #2: Unless you are an expert PHP and WP web developer who has used WP multisite _extensively_, then please don’t reply.

    Your welcome, we love giving up our spare time to help others 🙂

    Maybe you’d like to join us more often and share your wisdom and knowledge, seeing as you know all the answers?

    And FYI, the functions you listed have nothing to do with permalinks, and you can get all of that info on any page, so your question is really rather void.

    Have a plesent evening 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Convert permalinks to site ID, blog ID, type (e.g. 'post'), and type ID’ is closed to new replies.