Skip to main content
5 of 5
Fix link to ticket
j-maas
  • 113
  • 3

Retrieve post ID from "querying" URL

Disclaimer: I can't post more than two links, yet...

I know there are many similar questions, but none of the solutions work for me.

My problem is that with the Live Composer Plugin (wordpress.org/plugins/live-composer-page-builder/) the url_to_postid() function does not return a post id for Live Composer's custom post types, e. g. "Partners", "Project", "Staff". The URL of the permalink for a project named "Testproject" by default has the form http://localhost/wordpress/?dslc_projects=testproject. This does not get resolved by url_to_postid() into a valid post ID.

The workaround is to set the permalink structure to something other than the default "plain" setting. Then url_to_postid() in fact does correctly resolve even LC's custom post types.

However I do not trust the user to remember this workaround. Heck, I don't even trust myself. Hence, I'd like to know, if there is a way to resolve the type of URL above.

I'm new to WordPress, therefore I have not yet messed around with the database directly, have not implemented custom taxonomies and have not provided custom rewrite rules. I don't even know, what the type of URL like http://localhost/wordpress/?dslc_projects=testproject is called, although it seems to me to provoke a query in the database to match the dslc_projects attribute to testproject.
I'd love to know if this type of URL has a name, so I can google it and learn about it. Also, if someone knows how to get the post ID using those URLs that would be even awesomer. :)


Edit: I've now probably found a little bug in url_to_postid(). The functions returns when it hits the following if-clause :

// Check to see if we are using rewrite rules
    $rewrite = $wp_rewrite->wp_rewrite_rules();

// Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
if ( empty($rewrite) )
    return 0;

I assume this is a bug, since apparently there can be rewrite rules on custom post type URLs, which should be detected here.

It is reported as ticket #38041.

j-maas
  • 113
  • 3