add unique string as custom-field to every post
There is a simplier way to do what you want to: function add_unique_post_identifier( $post_id ) { $unique_post_identifier = get_post_meta($post_id, ‘unique_post_identifier’, true); // do nothing if post type is not ‘post’ or identifier is already set if (‘post’ != get_post_type( ( $post_id ) ) || !empty($unique_post_identifier) ) return; $generated_id = uniqid(); update_post_meta($post_id, ‘unique_post_identifier’, $generated_id); } // … Read more