I checked all subjects in forum about this but i didn't found way to resolve my problem. sorry for my english, i'm french.. :)
So.. i got a custom post listing ( with template listing pro ) there : /
I created a custom post named service and i display all service associate on listing on the listing single page. When i click on a service, i display his data on the same page with a GET
parameter ( the service id ) like this : /?show_service=196
But i need the name of service instead of show_service=196
after the name of listing "easy-office-lille"
How can i do that ? I'm really lost in url rewriting
I use Custom post type UI plugin to create custom post, I added rewrite option to true, and Custom Rewrite Slug option to service and registered permalink but that didn't work.
Thanks for help !
I checked all subjects in forum about this but i didn't found way to resolve my problem. sorry for my english, i'm french.. :)
So.. i got a custom post listing ( with template listing pro ) there : http://easycowork.fr/bureau/easy-office-lille/
I created a custom post named service and i display all service associate on listing on the listing single page. When i click on a service, i display his data on the same page with a GET
parameter ( the service id ) like this : http://easycowork.fr/bureau/easy-office-lille/?show_service=196
But i need the name of service instead of show_service=196
after the name of listing "easy-office-lille"
How can i do that ? I'm really lost in url rewriting
I use Custom post type UI plugin to create custom post, I added rewrite option to true, and Custom Rewrite Slug option to service and registered permalink but that didn't work.
Thanks for help !
To achieve result for custom URL rewriting for your custom post type service
using the Custom Post Type UI plugin,
you can follow these steps
Register the custom post type with the desired rewrite slug
Register Custom Post Type with Rewrite Slug:
In the Custom Post Type UI plugin, go to
CPT UI
>Add/Edit Post Types
and edit your"service"
post type. Make sure you have set theRewrite
option to true and theCustom Rewrite Slug
option to the desired slug,e.g( service )
Add a rewrite rule to handle the custom URL structure
Add a custom rewrite rule to handle the custom URL structure. You can do this by adding code to your themes
functions.php
file or acustom plugin
function custom_rewrite_rule() {
add_rewrite_rule(
'^bureau/([^/]+)/([^/]+)/?$',
'index.php?pagename=$matches[1]&show_service=$matches[2]',
'top'
);
}
add_action('init', 'custom_rewrite_rule');
This rule will rewrite URLs like http://easycowork.fr/bureau/easy-office-lille/123
to http://easycowork.fr/index.php?pagename=bureau/easy-office-lille&show_service=123
Modify your template to handle the custom URL structure
In your template file
single-service.php
, you can retrieve the service ID from the show_service parameter and display the corresponding content.
$service_id = isset($_GET['show_service']) ? intval($_GET['show_service']) : 0;
if ($service_id) {
// Query the service post based on the ID and display its content
// Example: $service_post = get_post($service_id);
} else {
// Display default content for the listing page
}
Remember to flush the rewrite rules after adding or modifying them. You can do this by visiting the "Settings" > "Permalinks"
page in your WordPress admin and clicking the Save Changes
button
After following these steps, you should be able to access your service pages with URLs like http://easycowork.fr/bureau/easy-office-lille/123
, where 123
is the ID of the service