function custom_rewrite_rules() {
add_rewrite_rule( '^product_brand/([^/]+)/page/([0-9]{1,})/?', 'index.php?product_brand=$matches[1]&page=$matches[2]', 'top' );
add_rewrite_rule( '^product_brand/([^/]+)/([^/]+)/page/([0-9]{1,})/?', 'index.php?product_brand=$matches[1]&product_cat=$matches[2]&page=$matches[3]', 'top' );
add_rewrite_rule('^product_brand/([^/]+)/([^/]+)?', 'index.php?product_brand=$matches[1]&product_cat=$matches[2]', 'top');
add_filter( 'query_vars', function( $vars ){
$vars[] = 'product_brand';
$vars[] = 'product_cat';
return $vars;
} );
}
add_action('init', 'custom_rewrite_rules');
and pagination
add_action( 'pre_get_posts', function() {
$page = get_query_var('page');
$query->set( 'paged', $page );
return $query;
} );
Related Posts:
- How can I modify the permalink via a filter?
- Newbie question: no index.php? in my plain wordpress permalink
- Change links automatically to affiliate links
- Rewrite sub folder dynamically with country code in WordPress using PHP
- Use WordPress’ URL rewrite engine
- Rename “Portfolio” slug?
- How to rewrite URL with PHP variables with htaccess to a normal looking URL?
- Static variable and add_rewrite_rule?
- Nesting if statements to echo only one string based on what tag was filtered?
- How to change home or site url using action hooks or filter?
- Why do WordPress rewriites seem to work differently for posts vs pages?
- Performance impact of rewriting WordPress URLs
- Is sanitize_title_with_dashes formatting function too liberal (in terms of accepted characters)?
- Changes in permalink structure in WordPress and how to apply to in-site links
- WordPress Persistent connection rule does not work for “posts”
- Append query string to all URL’s
- custom rewrite rule help! Custom rewrite rules not applying to custom post type
- subdirectory index.php is not working
- Use URL Rewrite as well as $_GET parameters in URL?
- How to modify URL (add GET values) after front end form submission?
- parts of url disappear when using # inside href=”” [closed]
- Create custom permalinks to show Custom Post Type’s relationship?
- Add .htm extention to a custom taxonomy
- Help with .htaccess and Login with Subfolders
- WordPress add_rewrite_rules for custom URLs ending in .html
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- Divi change project category slug
- How to add a rewrite endpoint to unattached media?
- How do i add slugs to a URL, but still redirecting to the same page
- Nginx WordPress and another Web app URL structure
- Custom post type url Rewrite (conflicting with page url)
- WordPress Rewrite Rule
- Why is home page content not displaying with this rewrite rule?
- Modifying WP URL handing code?
- How to deal with a GET variable of ‘name’?
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- How to pass username in affiliate link in wordpress website
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- url not using query string no longer working
- Current WordPress Page Title as Search Parameter into A Tag
- How does one make a URL return dynamic JSON with custom Content Type?
- How does WordPress rewrite URLS using its PHP scripts
- How can I turn a url with get method as a clean url with segment as the get method?
- WordPress Rewrite Issue
- How to print redirected query string variables to the page?
- Multiple URL from Custom post name
- Why isn’t my custom function kicking in from my functions.php file?
- Difference in Get Variable Location
- WordPress adding in site URL to header links
- Dynamically append custom post type to end of url
- WordPress add parameters with friendly url structure
- Custom taxonomy with page post type – WordPress
- count() parameter must be an array or an object that implements countable in laravel
- Receiving Stripe Webhooks on a wordpress website
- Sorting list of sites from multisite network using wp_get_sites
- Remove Customize Background and Header from Appearance admin menu without CSS or JS
- How do I get the author’s page url from their ID?
- Correct use of curly braces vs alternative synax
- Missing Author Information
- How can I set custom order use this function
- Check if Product is in a Specific Category in Functions.php
- How to generate HMAC-SHA1 signature to use with WP REST API and OAuth1
- How to send user data in json format to another server when user register on wordpress site in PHP
- Fetch posts from category in custom page template
- How do you use WP slugs for PDF files / media?
- How to properly loop through these external URLs to get them into the sitemap using this hook
- Custom shortcode outputs plain text instead of HTML at top of post
- Gravity form built in Captcha
- add_theme_page to add_menu_page theme options convert
- WordPress Scripts Being Loaded in Footer
- Jquery function working in Dev Console but not otherwise [duplicate]
- Headers already sent in Pluggable.php / homepage and wp-login error
- Unique session WordPress
- Can i put my shortcode inside a variable in php files?
- How to fix “Object of class WP_Term could not be converted to string”?
- Only show image from custom field when present
- Loading two post layouts for the same post with different url
- How do I populate custom field with current user role in Woocommerce [closed]
- When echo follow Ajax button inside Ajax pagination template not working?
- jQuery Ajax PHP function call returning [object Object]
- Add category to post meta
- Can I remove or edit an include() from a function with a filter?
- I want to include a particular word into the excerpt of every posts of a custom post type. How can I do that pragmatically?
- Disclaimer that will show every refresh of the page
- Woocommerce My acount page
- Pages from admin dasboard missing after site migration
- Menu not updating for logged in users after redirect
- New user – Create a folder
- How To Add Custom User Meta During Registration
- How can I create a shortcode from an html and php code written together
- Create custom admin page with custom text fields
- List categories assigned to a post
- Call get_template_part() custom permalink
- Display Year and Month from custom field + Age Calculator
- php string inside shortcode does not work
- No Authors for custom post type
- How to pass username into form that sends data to database
- which php or css file has generated an inline style in WordPress that overwrites my css
- Change body_class() PAGE to HOME
- PHP $_SESSION array – only showing current index