1

I've changed the permalinks to add a string at the beginning of the url like this: /london/%postname%/ This works perfect for all the pages but not for my home page.

I set my home page to be a single custom post type in settings->reading->static page so the url was like this: http://example.org/destination/london

But now it's: http://example.org/london/destination/london

How can i change it so the home page is just the single custom post type without the "/destination/london" part?

Edit:

After adding this code it almost work:

function enable_front_page_destination( $query ){
    if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
        $query->query_vars['post_type'] = array( 'page', 'destination' );
}
add_action( 'pre_get_posts', 'enable_front_page_destination' );

But now the home url is http://example.org/ and it should be http://example.org/london

Thank you.

0

EDIT Since, as you mentioned it in comments, it can have several values, maybe we could retrieve the city list and set corresponding rewrite rules like so?

assuming $city_list is an array of cities

foreach ($city_list as $city) {
    add_rewrite_rule('/^'. $city .'/destination/'. $city .'$/','index.php?p=idofyourhomepage','top');
}

How about trying some rewrite rules.

add_rewrite_rule('/^london/destination/london$/','index.php?p=idofyourhomepage','top');

Or

add_rewrite_rule('/^london/destination/london$/','index.php?pagename=nameofyourhomepage','top');

Go validate your permalink settings to refresh the rules.

  • london is a custom post type so it can have the value london, paris, madrid, etc – Oterox Oct 17 '18 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.