vendredi 13 mars 2020

Sharing the same slug in Custom post type, With Dynamic Slug

Right now i am facing a problem, with custom post type. with custom slug archieve is set as false.

$args['rewrite'] = array(
            'slug' => '/%hotel%/details',
            'with_front' => false
          ); 
http://localhost/hotel/en/bubble-bubble/details/rooms/
petra-bubble = hotel
rooms = page name

so we have multiple hotel's but i want that room slug should remain same like one page of room for bubble-hotel second page of room for tubble-hotel

i am trying to hack with two actions hooks

add_action('parse_request', 'overwriteRequest', 10, 1);
function overwriteRequest($query) {
 ????
}
add_action( 'pre_get_posts', 'vipx_parse_request_tricksy' );

function vipx_parse_request_tricksy( $query ) {

    // Only noop the main query
    if ( ! $query->is_main_query() )
        return;

    if ( ! empty( $query->query['name'] ) )
        $query->set( 'post_type', array(CUSTOM_POST_TYPE_POSTING,  CUSTOM_POST_TYPE_RESTAURANT,  CUSTOM_POST_TYPE_ROOM, CUSTOM_POST_TYPE_HOTEL ,DEFAULT_POST_TYPE_PAGE, DEFAULT_POST_TYPE_POST ) );
}

but i didnt get how can i achieve it ?

result i want is

http://localhost/hotel/en/bubble-bubble/details/rooms/
http://localhost/hotel/en/tubble-hotel/details/rooms/
http://localhost/hotel/en/third-hotel/details/rooms/

Now in %hotel% is different for all pages but the room slug is same

now i can save the same slug but i can't parse the query and page so that i can get the different page result and content as per hotel selected



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire