Why does a custom post type need the ”hierarchical’ args setting?

When you have two content objects with a similar interface or shared properties, you have a good candidate for hierarchical post types. Take places as an example (see this answer): Asia Europe Germany Berlin Austria Vienna Each place has similar meta data: population, geo coordinates, spoken languages. You just can reuse the same interface. Plus, … Read more

Update URL Snippet to Canonical Permalink URL

Why? I think the reason why a) domain.com/123 is not redirected back to b) domain.com/123/post-slug with the /%post_id%/%postname%/ permalinks settings, is that the matched rule is: [matched_rule] => ([0-9]+)(/[0-9]+)?/?$ You can get that information from the global $wp object. There are other useful informations in $wpavailable after the wp action: Example (post): domain.com/123/post-slug/ [query_vars] => … Read more

Why don’t WordPress post slugs allow accents?

The sanitize_title() function uses remove_accents() right away. Both of these functions date way back to <= v1.2.1. The remove_accents() function is a hard coded list of accent characters to explicitly replace a handful of characters in a few specific languages. The inline comment and function reference simply say: Converts all accent characters to ASCII characters. … Read more

‘publicly_queryable’ => false not working as expected for custom post_type

If you want archives, but not singular view, then ‘publicly_queryable’ can’t help you. If you want that visiting a singular post send a 404… just do it. You can hook ‘template_redirect’ and manually set the 404: add_action( ‘template_redirect’, function () { if (is_singular(‘tattooer’)) { global $wp_query; $wp_query->posts = []; $wp_query->post = null; $wp_query->set_404(); status_header(404); nocache_headers(); … Read more

Post titles not letting me use 2 consecutive dashes in permalink

Regarding the why part, I think I’ve traced this to the following line: $title = preg_replace(‘|-+|’, ‘-‘, $title); within the sanitize_title_with_dashes() function. It’s added to the santize_title() via the filter: add_filter( ‘sanitize_title’, ‘sanitize_title_with_dashes’, 10, 3 ); but I wouldn’t recommend removing it totally. Update: Here’s a quick and dirty way around this: add_filter( ‘sanitize_title’, function( … Read more

Refresh page after form action

Searching around and not being able to implement the action through init hook I’ve found this workaround which for sure isn’t the best but does the job nicely. echo “<script type=”text/javascript”> window.location=document.location.href; </script>”; at the end of $_POST instructions. If somebody has a better solution, welcome to share.

‘post_type_link’ filter not working

It is not a bug. As @LuisSanz pointed out, post_type_link isn’t used for the built-in post post type. It is used for custom post types only. Skim through get_permalink() function, you will find out that WordPress doesn’t use post_type_link filter but uses post_link filter. It means that you’re using wrong filter. Then, change post_type_link to … Read more