Pagination problem

I have two custom rewrite rules: add_rewrite_rule(‘foo/bar/?’, ‘index.php?post_type=foo’, ‘top’); add_rewrite_rule(‘foo/bar/([a-z]+)/?’, ‘index.php?post_type=foo&bar=$matches[1]’, ‘top’); Which gives me posts that match a custom variable bar. However, I want to handle pagination too, thus when a number succeeds /bar/ wordpress should treat it as a page number. I wrote: add_rewrite_rule(‘foo/bar/([0-9]+)/?’, ‘index.php?post_type=foo&paged=$matches[1]’, ‘top’); In my custom function which is attached … Read more

add_rewrite_rule query_var not being set

I have an unusual use of add_rewrite_rule (is there a usual use?) and I am getting some unexpected behavior. First here is my code: if(!empty($list_view_template)) add_rewrite_rule( “{$list_view_template}/(.*)?”, ‘index.php?mlscrit=$matches[1]/list-view/&pagename=” . $list_view_template, “top’ ); add_filter(‘init’, ‘mls_declare_mls_custom_vars’); function mls_declare_mls_custom_vars() { add_rewrite_tag( ‘%mlscrit%’, ‘(.*)’ ); } so as you can see I am using a pagename set within the … Read more

add_rewrite_endpoint() and Custom Post Type Archive

I’ve got a custom post type. Let’s call it books. I’m adding a new rewrite endpoint called pages. I want the url /books/pages/2/ to work but I don’t see any rewrite rules generated by WordPress for this. I can manually add the rewrite rules for this specific example, but I’m looking for a way to … Read more

add_rewrite_rule not registering on Multisite

I have a multisite install of WordPress. I have installed the plugin Monkeyman Rewrite Analyzer so I can see all the rules I have registered. The code below is how I am registering the rule: add_action( ‘init’, ‘add_init_rules’ ); function add_init_rules() { add_rewrite_rule(‘^car/([^/]*)/([^/]*)/?’,’index.php?pagename=car&id=$matches[1]&make=$matches[2]’,’top’); } The rule I have added does not appear in the Monkeyman … Read more

How to Combine Two Custom Post Types into Single Permalink Structure

The website uses – A) A hierarcical Custom Post Type “Destination” to support the following structure, so each tier of the hierarchy could have its own unique destination guide: Territory – Americas Continent – North America Section – Country – United States Region – State – New York Area – City – New York City … Read more

How to add rewrite rules and pagination to retrieve attachments files?

I’m trying to list attachments based on different taxonomies. Right now it only work for the basic url (no pagination added). For example http://www.example.com/exams/high-school/city-name/subject/math/ First, I added my custom rewrite rule in functions.php as follows: function add_rewrite_rules($aRules) { $new_rules = array( // rule 1 ‘exams/([^/]+)/([^/]+)/subject/([^/]+)/?$’ => ‘index.php?pagename=exams&level=$matches[1]&city=$matches[2]&subject=$matches[3]’, // rule 2 ‘exams/([^/]+)/([^/]+)/subject/([^/]+)/page/([0-9]+)/?$’ => ‘index.php?pagename=exams&level=$matches[1]&city=$matches[2]&subject=$matches[3]&page=$matches[4]’ ); return … Read more

Add hierarchical taxonomy to permalink for custom post type

I’ve found various questions about this issue, and I still can’t get this to work. I have a post type called “product” and a taxonomy called “type”. I’d like the URL for a single product post to be: mysite.com/product/type/subtype/postname/ By default, it is: mysite.com/product/postname/ I’ve tried every example I’ve found. Some say all you have … Read more

Rewrite URL – insert custom variables as a directory path

I’m trying to re-write permalink structure with my own custom url in WordPress for a Divi Theme “project” I have already changed the “Divi slug” from “project” to “prodotti” so currently, the URL appears like this: http://www.example.com/prodotti/%postname%/ with my custom function function custom_post_name() { return array( ‘feeds’ => true, ‘slug’ => ‘prodotti’, ‘with_front’ => false, … Read more

.htaccess rewrite rule puzzle

Because I need to password protect a subdirectory using cPanel, I modified WordPress’s .htaccess rule as instructed here: https://wordpress.org/support/topic/password-protect-a-directory-with-htaccess This is my current wordpress rewrite block: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ./ /index.php [L] </IfModule> # END WordPress Notice particularly … Read more