2

For attachment posts, the following should do it, i.e. use the wp_insert_attachment_data hook along with get_post(): function my_random_post_id( $data, $postarr ) { // Runs if the post is being created and not updated. if ( empty( $postarr['ID'] ) ) { // Locate a yet-unused ID in the (wp_)posts table. do { // Based on ...


1

I am too late to answer this question but it will worked. $attachment_id = get_post_thumbnail_id( $post->ID ); $url = wp_get_attachment_image_src($attachment_id, 'desired-size');


Only top voted, non community-wiki answers of a minimum length are eligible