You need to create query_var
for sector
and you need to create a rewrite rule with RegEX. I created a plugin for this. Create a file and add into the wp-content/plugins
folder and activate it.
<?php
/*
Plugin Name: Custom Rewrite
Plugin URI: https://serkanalgur.com.tr
Description: Custom Rewrite
Version: 1
Author: Serkan Algur
Author URI: https://www.serkanalgur.com.tr
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
class FilterRewriteRule
{
public function init()
{
$this->InitRewriteRules();
add_filter('query_vars', [$this,'add_query_for_sector']);
add_filter('template_include', array($this, 'filter_template'), 99);
}
private function add_query_for_sector($vars)
{
$vars[] = 'sector';
return $vars;
}
private function InitRewriteRules()
{
add_rewrite_rule(
'products/import/([^/]*)/?$',
'index.php?pagename=products/import§or=$matches[1]',
'top'
);
add_rewrite_rule(
'products/import/page/([0-9]{1,})/([^/]*)/?$',
'index.php?paged=$matches[1]&pagename=products/import§or=$matches[2]',
'top'
);
}
public function filter_template($template)
{
global $wp;
if (get_query_var('sector') && is_page('import')) {
$custom_template = locate_template('sector.php');
if ($custom_template) {
return $custom_template;
}
}
return $template;
}
}
register_activation_hook(__FILE__, function () {
$writing_ideas = new FilterRewriteRule();
$writing_ideas->init();
flush_rewrite_rules();
});
add_rewrite_rule
add the rewrite rule with pagination support. filter_template
locate your sector.php
file and redirect the request to this file. query_vars
adds sector
query to WordPress system.