Create unique alphanumeric ID on wp_insert_post

See here the working version // function to save the randomString as custom field value function generate_AlphanumericID( $post_id ) { $postTypes = array(‘profile’, ‘article’); $postType = get_post_type( $post_id ); if (in_array( $postType, $postTypes ) ) { $characters = “0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ-_~’!,”; $charactersLength = strlen($characters); $randomString = ”; for ($i = 0; $i < 11; $i++) { $randomString … Read more

Changing post content on save, using updated fields

Try to use the post object provided by the action as the second parameter instead of getting it from database: function change_event_slug_on_save( $post_id, $post ) { … } add_action( ‘save_post’, ‘change_event_slug_on_save’, 10, 2 ); With this you can remove the line $post = get_post($post_id); EDIT: Tribe Events Calendar has it’s own actions for saving an … Read more

Force pretty permalinks?

Not exactly the solution you’re asking for, but here’s how I would deal with such problem… If your plugin needs permalinks to be turned on, then I would put some checks and display a notice, if they’re not turned on. I don’t think that plugin should force anything. There can be a lot of reasons … Read more

how to add two same slug under two category?

Reason for such behavior lies in wp_insert_post function. When you look at its code, on line 3319 you’ll see this line: $post_name = wp_unique_post_slug( $post_name, $post_ID, $post_status, $post_type, $post_parent ); And what this function does is (straight from Codex): Computes a unique slug for the post, when given the desired slug and some post details. … Read more

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