Using a variable in page permalink

As I said, the permalink changes from YEAR_NAME to 2023, but the link gets 404 error Yes, and it’s because the post slug no longer matched the value in the database (in the wp_posts table, column post_name), hence the permalink URL became invalid and WordPress displayed a 404 error page. So you need to add … Read more

What is the best way to relate different custom post types?

I think a better approach for this would be to create a single nested (hierarchical) custom post type. For example, it can be series. Then a single series named sample-series as a top level post of series post type: site.com/series/sample-series/. Then seasons named season-one, season-two etc. can be children of sample-series, like: site.com/series/sample-series/season-one, site.com/series/sample-series/season-two. Similarly, … Read more

WordPress not remembering old slugs for pages

WordPress keeps track of post slug change with wp_check_for_changed_slugs() function. The old slugs are saved in wp_postmeta table with _wp_old_slug meta_key and later redirects to current URL with wp_old_slug_redirect() function. That’s why even after changing a post’s slug, you get redirected to the correct post. However, WordPress doesn’t do this by default with pages (or … Read more

Can you customize the automatic permalink population on new posts?

you can use the post_type_link hook. and then add a custom rewrite rule to your register_post_type function: function replace_post_link( $post_link, $id = 0 ){ $post = get_post($id); $post_type = get_post_type( $id ); if( is_object( $post ) && $post_type == ‘events’ ){ $custom_date = get_field(‘YOUR_CUSTOM_FIELD’); return str_replace( ‘%custom_date%’ , $custom_date, $post_link ); } return $post_link; } … Read more