CPT-onomies: Using Custom Post Types as Taxonomies
[resolved] Archive Page Slug problem (5 posts)

  1. toojee
    Posted 2 years ago #


    I have trouble to understand how CTP-onomies works with archive page.
    I have a CPT "hotel" and another CPT "city".
    In CPT-onomies city I have checked the "Attach to Post Types" hotel to get city at the right of admin post hotel. That works and that ok.

    But for the Archive Page Slug for all hotel in a city I want "www.domain.com/hotel/city/new-york" for example. But in city cpt archive slug i have "www.domain.com/city/tax/new-york".

    It is possible to that with this plugin?
    Because the $post_type refer to city and not to hotel... In fact I will use city with another CPT later like house for example. I will need with same CPT city "www.domain.com/house/city/new-york" to show just the house in new york.



  2. Rachel Carden
    Plugin Author

    Posted 2 years ago #

    I'd check out the documentation for Custom CPT-onomy Archive Pages. I think you'll find your answer there.

  3. toojee
    Posted 2 years ago #

    Thanks for the answer!

    I wrote this rule in functions.php :
    add_rewrite_rule( "^hotel/city/([^/]*)/?", "index.php?post_type=hotel&city=$matches[1]&cpt_onomy_archive=1", "top" );

    When i go in url like "www.domain.com/hotel/city/new-york/" I have a archive page but not whith the hotels in new york city. I have listed all the hotels in all cities. In the sql query I don't see city involve.

    "city" is of course a post type attach to post type "hotel".
    I need to do something more to make this working?

  4. toojee
    Posted 2 years ago #

    Ok sorry I find my problem!
    With help of Rewrite Rules Inspector plugin I see I use double quotes intead of simple quote in add_rewrite_rule, so php convert $matches[1] to nothing.

    This works perfectly!

  5. Rachel Carden
    Plugin Author

    Posted 2 years ago #

    Awesome! Glad you figured it out!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic