url rewriting - Rewrite url for custom post type with specific url

admin2025-06-06  1

I have a custom post types called Destinatiosn. These post on click opens as pages and they are organised hierarchically. Example:

  • Malaga

    • Food
    • Gallery
    • Rooms
  • Marbella

    • Food
    • Gallery
    • Rooms

Now in Rooms page, I am selecting to use other custom post types called "Room". In this page I will show selected custom post types. But my problem is that when I click on these custom post types URL is changing. I just want to add on existing url only the name of the room.

Example, I am in this page:

/marbella/rooms

On room custom post type click, I want room to be:

/marbella/rooms/room-name

But when I click Url changed to:

/room/room-name

function add_page_rewrite_rules(){ $url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/'); $wp_rewrite->add_permastruct( 'room', $url_path . '/%room%', false ); }

But if I change url to something else working, when I am using example /malaga or /marbella it is not working and I don't know why ?

How can I resolve my problem ?

My question here is a unique because I have added a sample of code and I do not know why url:

$wp_rewrite->add_permastruct( 'room', $url_path . '/%room%', false );

is not working but when I change to some url which does not exist works.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749141057a316713.html

最新回复(0)