Execute wp_after_insert_post after the permalink is customized

To execute update_post_meta after the permalink is customized, you can use the save_post hook instead of wp_after_insert_post. Here’s how you can modify your code: add_action(‘save_post’, ‘add_permalink_to_new_post’, 10, 2); function add_permalink_to_new_post($post_id, $post) { // Check if this is a new post if ($post->post_date_gmt == $post->post_modified_gmt) { // Only run this on a newly created post update_post_meta($post_id, … Read more

Modify Post URL Programmatically

When you are using wp_insert_post() there is a param post_name. If you do not pass it then it will sanitise your post title and update. You only have control to add post_name but the full URL is created based on your Permalink settings.

How to automatically flush permalinks?

To automatically flush permalinks every hour, use the following code: Hook the scheduling function to init. Schedule an hourly event if not already scheduled. Hook the scheduled event to a function. Define the function to flush rewrite rules. // Hook the scheduling function add_action( ‘init’, ‘schedule_my_hourly_event’ ); // Schedule the event function schedule_my_hourly_event() { if … Read more

Custom Post Types Do Not work on this permalink setting https://somedominaname.com/%category%/%postname%/

The Permalink structure setting on the Permalink Settings admin page is only applied to the default post type, i.e. post. For custom post types (CPTs), you can set the permalink structure (for posts in your CPT) when registering your CPT, via the rewrite argument for register_post_type(). But, if you want to use %category%/%postname% with your … Read more

How to Set Both Category and Sub-Category Level at Root. It should also obey post rule as /category/sample-post and /sub-catgeory/sample-post?

You’ll need to define your own rewrite tag, and add the tag into the permalink structure. add_rewrite_tag() to register the new structure tag available_permalink_structure_tags filter to add to Permalinks interface post_link filter to change the URL of posts Below is untested and incomplete code, but should get you pretty far. add_action( ‘init’, static function () … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)