$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>permalinks - Custom post type as home page with custom url|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

permalinks - Custom post type as home page with custom url

matteradmin8PV0评论

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:

But now it's:

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 / and it should be

Thank you.

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/destination/london

But now it's: http://example/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/ and it should be http://example/london

Thank you.

Share Improve this question edited Oct 10, 2018 at 9:32 Oterox asked Oct 10, 2018 at 9:04 OteroxOterox 3521 gold badge4 silver badges13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

Post a comment

comment list (0)

  1. No comments so far