Skip to main content
Fix link to ticket
Source Link
j-maas
  • 113
  • 3

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#38041.

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.

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.

Summarize
Source Link
j-maas
  • 113
  • 3

Edit: I've dug into the code of the plugin and the WordPress database. I've found that dslc_projectsis the post_type and testproject is the post_name. I later also found out that the plugin uses what I suppose to be costum rewrite rules when registering its post types (code taken from public respository):

// Arguments
    $tax_args = array( 
        'labels' => array(
            'name' => __( 'Projects Categories', 'live-composer-page-builder' ),
            'singular_name' => __( 'Category', 'live-composer-page-builder' ),
            'search_items'  => __( 'Search Categories', 'live-composer-page-builder' ),
            'all_items' => __( 'All Categories', 'live-composer-page-builder' ),
            'parent_item' => __( 'Parent Category', 'live-composer-page-builder' ),
            'parent_item_colon' => __( 'Parent Category:', 'live-composer-page-builder' ),
            'edit_item' => __( 'Edit Category', 'live-composer-page-builder' ),
            'update_item' => __( 'Update Category', 'live-composer-page-builder' ),
            'add_new_item' => __( 'Add New Category', 'live-composer-page-builder' ),
            'new_item_name' => __( 'New Category Name', 'live-composer-page-builder' ),
            'menu_name' => __( 'Categories', 'live-composer-page-builder' ),
        ),
        'hierarchical' => true, 
        'public' => true, 
        'rewrite' => array( 
            'slug' => dslc_get_option( 'projects_cats_slug', 'dslc_plugin_options_cpt_slugs' ),
            'with_front' => $with_front
        ), 
        'capabilities' => array(
            'manage_terms' => $capability,
            'edit_terms' => $capability,
            'delete_terms' => $capability,
            'assign_terms' => $capability,
        ),
    );

    // Apply filters
    $tax_args = apply_filters( 'dslc_projects_cats_args', $tax_args );

    // Register Taxonomy
    register_taxonomy( 'dslc_projects_cats', 'dslc_projects', $tax_args );

Since it simply registers a slug, I suppose that WordPress is responsible for the format of the URL (unless the plugin rewrites the URL somewhere else again).

What are some ressources to learn how to deal with these slugs?


Edit: I've now probably found a little bug in url_to_postid(). The functions returns when it hits the following if-clause (core.trac.wordpress.org/browser/tags/4.6/src/wp-includes/rewrite.php#L509)following if-clause :

Edit: I've dug into the code of the plugin and the WordPress database. I've found that dslc_projectsis the post_type and testproject is the post_name. I later also found out that the plugin uses what I suppose to be costum rewrite rules when registering its post types (code taken from public respository):

// Arguments
    $tax_args = array( 
        'labels' => array(
            'name' => __( 'Projects Categories', 'live-composer-page-builder' ),
            'singular_name' => __( 'Category', 'live-composer-page-builder' ),
            'search_items'  => __( 'Search Categories', 'live-composer-page-builder' ),
            'all_items' => __( 'All Categories', 'live-composer-page-builder' ),
            'parent_item' => __( 'Parent Category', 'live-composer-page-builder' ),
            'parent_item_colon' => __( 'Parent Category:', 'live-composer-page-builder' ),
            'edit_item' => __( 'Edit Category', 'live-composer-page-builder' ),
            'update_item' => __( 'Update Category', 'live-composer-page-builder' ),
            'add_new_item' => __( 'Add New Category', 'live-composer-page-builder' ),
            'new_item_name' => __( 'New Category Name', 'live-composer-page-builder' ),
            'menu_name' => __( 'Categories', 'live-composer-page-builder' ),
        ),
        'hierarchical' => true, 
        'public' => true, 
        'rewrite' => array( 
            'slug' => dslc_get_option( 'projects_cats_slug', 'dslc_plugin_options_cpt_slugs' ),
            'with_front' => $with_front
        ), 
        'capabilities' => array(
            'manage_terms' => $capability,
            'edit_terms' => $capability,
            'delete_terms' => $capability,
            'assign_terms' => $capability,
        ),
    );

    // Apply filters
    $tax_args = apply_filters( 'dslc_projects_cats_args', $tax_args );

    // Register Taxonomy
    register_taxonomy( 'dslc_projects_cats', 'dslc_projects', $tax_args );

Since it simply registers a slug, I suppose that WordPress is responsible for the format of the URL (unless the plugin rewrites the URL somewhere else again).

What are some ressources to learn how to deal with these slugs?


Edit: I've now probably found a little bug in url_to_postid(). The functions returns when it hits the following if-clause (core.trac.wordpress.org/browser/tags/4.6/src/wp-includes/rewrite.php#L509):

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

Add details
Source Link
j-maas
  • 113
  • 3

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 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.

What are some ressources to learn how to deal with these slugs?


Edit: I've now probably found a little bug in url_to_postid(). The functions returns when it hits the following if-clause (core.trac.wordpress.org/browser/tags/4.6/src/wp-includes/rewrite.php#L509):

// 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.

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

My problem is that with the Live Composer Plugin 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.

What are some ressources to learn how to deal with these slugs?

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.

What are some ressources to learn how to deal with these slugs?


Edit: I've now probably found a little bug in url_to_postid(). The functions returns when it hits the following if-clause (core.trac.wordpress.org/browser/tags/4.6/src/wp-includes/rewrite.php#L509):

// 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.

Append further details
Source Link
j-maas
  • 113
  • 3
Loading
Source Link
j-maas
  • 113
  • 3
Loading