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.
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 dug into the code of the plugin and the WordPress database. I've found that dslc_projects
is 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?