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.

  • 1
    If you have a question about the inner workings of a third party plugin, you have a better chance of getting an answer at its author's forum
    – cjbj
    Sep 13, 2016 at 12:05
  • Isn't this type of URL also what is used with the plain permalink option such as http://localhost/wordpress/?p=123? Only that that it is another attribute, p? If it is so, then maybe it is possible to query the database for the attribute dslc_projects. Do you know any ressources on that?
    – J0hj0h
    Sep 13, 2016 at 12:13

1 Answer 1


Try This Code

 $latest = new WP_Query( array (
    'post_type'    =>'your-post-type-name',
    'post_status'  =>'publish',
    'orderby'               => 'rand',
    'posts_per_page'        => 3

    while ( $latest -> have_posts() ) : $latest -> the_post();
    echo the_ID();
  • 1
    I don't understand, what the code is doing. Is it loading the pages and then getting the ID? Also, is it possible to get the post type from the URL?
    – J0hj0h
    Sep 13, 2016 at 12:15
  • simple you can define post type on 'post_type' => 'name of post type slug' Sep 13, 2016 at 12:17
  • This seems to be loading the the post information into the $post global, which seems "overkill". (developer.wordpress.org/reference/classes/wp_query/…) Is there a way to search the database for the attribute?
    – J0hj0h
    Sep 13, 2016 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.