Same name for custom post and custom taxonomy (3 posts)

  1. staurand
    Posted 5 years ago #

    I have a problem since I have upgraded my WordPress from 3.0 to 3.1
    I used custom posts and custom taxonomies. Some of them have the same name.
    For example I have a custom post named "theme" and a custom taxonomy named "theme" too ;)
    I don't think it is not allowed. (?)

    if it is "not allowed" close my post :)

    In the admin if you use this URL:
    You should have a list of all custom posts "illustrations" in the "brand-positioning" which is a term of "theme" taxonomy.
    It does not work since 3.1
    If you try something similar you will have "No posts found."

    The problem comes from these lines in /wp-includes/class-wp.php (function parse_request):

    if ( isset($post_type_query_vars[$wpvar] )) {
    					$this->query_vars['post_type'] = $post_type_query_vars[$wpvar];
    					$this->query_vars['name'] = $this->query_vars[$wpvar];

    So here the code thinks "theme" is a post type and add to the query "name" => "brand-positioning".
    It is like the deprecated 'my_taxonomy' => 'my_term'
    ( see http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters )
    I don't think that 'my_custom_post_name' => 'my_post_name' is documented.

    It worked in WP 3.0 because the feature "'my_taxonomy' => 'my_term'" was not removed and the code above was testing if the taxonomy existed before the custom post. (So I was lucky...)

    I don't know if it the code above should not be there or if the URL should have others parameters.

    Thanks for any response.

  2. evandavidpaul
    Posted 5 years ago #

    I have gotten myself in a similar situation. I deliberately named a custom tax the same thing as a custom post_type and was using the posts that had the assigned custom tax to pull information from the corresponding custom post_type. This part worked great, but now I would like to display the custom post type itself.

    If i just click "view post" from the edit screen it gives me a 404.

    What is the rule we are breaking here? are their workarounds?

  3. staurand
    Posted 5 years ago #

    2 things:
    * for "I would like to display the custom post type"
    You are going to have 2 similar URLs. If you want to have both accessible you need to have 2 real different permalinks.
    You can play for example with "with_front" parameter of "register_taxonomy". See http://codex.wordpress.org/Function_Reference/register_taxonomy
    You have also similar things with "register_post_type"
    It seems that if you have a permalink structure like "/%category%/%postname%/":
    "/myCustomTaxonomy/myTermSlug/" will override "/myCustomPostType/myPostName" (with myCustomTaxonomy == myCustomPostType && myTermSlug == myPostName)

    * for 404 check : http://seanbehan.com/programming/how-to-flush-your-permalink-structure-in-wordpress-when-using-taxonomies-or-wordpress-taxonomies-not-working-instead-i-see-a-404-page/

    I hope it will help you.

Topic Closed

This topic has been closed to new replies.

About this Topic