I'm registering a custom taxonomy for my blog using the register_taxonomy function which has an argument rewrite
for rewrite the URLs using some parameters
, one of them is ep_mask
. Wordpress claims that it should be used when you want to add an endpoint for the Taxonomy URL. I just don't understand why to add an endpoint and what it's benefit. Please if an example with a result is available it will be better.
Thanks in advance
In WordPress, you can create (or “register”) a new taxonomy by using the register_taxonomy() function. Each taxonomy option is documented in detail in the WordPress Codex. After adding this to your theme's functions. php file, you should see a new taxonomy under the “Posts” menu in the admin sidebar.
' So make sure you have a custom post type created before you begin creating your taxonomies. Next, go to CPT UI » Add/Edit Taxonomies menu item in the WordPress admin area to create your first taxonomy. On this screen, you will need to do the following: Create your taxonomy slug (this will go in your URL)
Taxonomies are the method of classifying content and data in WordPress. When you use a taxonomy you're grouping similar things together. The taxonomy refers to the sum of those groups. As with Post Types, there are a number of default taxonomies, and you can also create your own.
MySQL to update the custom taxonomy name in WordPressUPDATE `wp_postmeta` SET `meta_value` = 'new-value' WHERE `meta_value` = 'old-taxonomy-name' ; Put your taxonomy values (old and new) in the code above. After executing this script your custom taxonomy items should reappear within your WordPress CMS.
The endpoint mask value is used to tell WordPress what kind of endpoint additions a certain registered item supports, and to which a developer can add
endpoints to via add_rewrite_endpoint()
.
By default taxonomies (as far as I know) offer no ep_mask
(defaults to EP_NONE
), but for custom taxonomies you could use a custom EP mask, or one of the built-in ones (e.g. EP_PAGES
) to make the permalink structure work similarly to something else.
Assuming you set the ep_mask
value to EP_PERMALINK | EP_PAGES
, you could then register a new endpoint using
add_rewrite_endpoint('json', EP_PERMALINK | EP_PAGES);
Which in turn would allow you to suffix your taxonomy URLs with json
and the value json
would be available as a query variable in $wp_query
. Then you can use the value as a check to alter the query, templates, and other related things when the page loads.
You can read more about endpoints here: https://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/ (A bit old, but should still reflect how the core works with endpoints.)
The benefit is that you can use the endpoint with pretty permalinks.
If you do not specify the EP_MASK, pretty permalinks will not work
The description of ep_mask
in the documentation of register_taxonomy()
contains a link to an article that explains it in detail.
A quote from that article:
If we wanted to add our endpoint to all post permalinks we would use
EP_PERMALINK
. For both posts and pages:EP_PERMALINK | EP_PAGES
. For posts, pages, and categories:EP_PERMALINK | EP_PAGES | EP_CATEGORIES
.
There are specific examples in that article:
https://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With