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
- Remove slug of multiple custom post types with and without hierarchical
- Getting the Current User
- Remove at the beginning of the_excerpt() with str_replace
- Uncaught TypeError: Cannot read property ‘firstChild’ of null after upgrading to WordPress 5.5
- WordPress if (is_page) translation on certain page
- Batch update a post meta field value of each post in Post Type
- How to restrict wp generate attachment metadata() to certain intermediate image sizes
- get post based on category chosen in drop down – The ajax method
- Extending the WP_Widget_Text class
- Display FNumber (aperture) as a number versus a fraction
- different id for same element visual composer [closed]
- user_profile_update_errors hook not executing
- Changing the default object embed sizes?
- Please help me with tag and php code [closed]
- Convert WordPress date format to jQuery UI Datepicker format
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- Don’t show certain div on front page?
- Deleting Certain terms from appearing on the front end as links
- Usage of call back function of add_meta_box()
- Menu Items fail to save correctly, cause reset of related page metadata
- How do I add more options to the post-new.php page?
- Four posts per row [closed]
- Genesis / custom template page / setting the page title and meta desc
- First post article different on Archives template
- Shortcode displaying at the top of the page [duplicate]
- Custom Fields Not Showing
- PHP variables in a post?
- Filter wordpress query by numerical order arguments
- Help to modify wp_link_pages()
- How to Insert Related Posts Inside WordPress Post Content
- Order category posts by last word of custom field
- How can I properly loop through an array gotten from my wordpress database and display it to my site
- I cannot find the wordpress.scss file that my live site is pulling from
- Redirect User when they click Menu Option
- How to create dynamic templates?
- How to create an unordered list of images separate from the content
- How to add delete, approve, spam Links to Comments
- Adding user meta to post meta wp_insert_post() not working
- Gravity Forms on submit return value on same page
- Showing the authors username and bio on custom author.php
- Help with my first Metabox helper class
- Splash pages on a high traffic site
- Dropdown Menu for Query_Posts
- How to add custom checkout field in user details mail template
- Fatal error: Uncaught Error: Call to undefined function wp_nav_menu()
- How to create a loop that will display one post and stop?
- How to align buttons properly [closed]
- index.php file keeps redirecting to a non-existent index.html file?