WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Convert permalinks to site ID, blog ID, type (e.g. 'post'), and type ID (6 posts)

  1. bigsite
    Member
    Posted 3 years ago #

    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?

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    There's isn't an inverse function.

  3. David Gard
    Member
    Posted 3 years ago #

    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!

  4. esmi
    Forum Moderator
    Posted 3 years ago #

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

  5. bigsite
    Member
    Posted 3 years ago #

    @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_id_from_blogname()
    get_blog_details()
    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.

  6. David Gard
    Member
    Posted 3 years ago #

    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 :-)

Topic Closed

This topic has been closed to new replies.

About this Topic