How WordPress turns URLs into queries and how to change it: rewrite rules and tags, terms in custom post type URLs, a /blog/ prefix for posts, and the slug conflicts that cause 404 errors.
How to update the slug automatically after the title changes We have a custom post type that is not shown on the site and in search, i.e. 'publicly_queryable' => false. For such a post type the admin does not show the permalink editor, so the slug cannot be edited there. But we use the slug…
Custom URL structures with add_rewrite_rule() and query variables Post types, taxonomies and endpoints produce their URLs automatically. When you need a structure that none of them gives, for example /docs/installation/requirements/ where the first part is a section and the second a document, you write the rule yourself: a regular expression for the path and the…
Rewrite rules in WordPress: custom post type slugs, endpoints and flushing WordPress turns pretty URLs into queries with a table of rewrite rules: regular expressions that map a path like /books/my-book/ to query variables like post_type=book&name=my-book. The table is generated by the WP_Rewrite class and stored in the rewrite_rules option. Custom post types, taxonomies and…
How to add a /blog/ prefix to the default posts Let’s imagine that you or your client use the default posts for the blog. As you know, in this case the post URLs do not contain any prefix: https://example.com/post-title/. But you need to add one, for example /blog/, to separate the blog from the pages…
How to add the term name to a custom post type permalink By default the permalink of a custom post type (CPT) contains only the post type slug and the post slug. But sometimes the URL has to contain the term too.
When we register new post type is recommended use names in the singular (e.g. default post types — post, page, etc.), but in some cases it's not always convenient.
WordPress pagination bug: the second page shows the same posts as the first A common pagination bug in custom loops: the page links look right, but page 2, page 3 and so on show exactly the same posts as page 1. The fix is one missing argument in the WP_Query call.