Site icon Hip-Hop Website Design and Development

Do customized submit kind (CPT) attachments/media retailer the father or mother submit ID? [closed]

Do customized submit kind attachments retailer the father or mother submit ID, and in that case, how do I retrieve it.

I’m utilizing a kind which permits registered customers to create a CPT (‘Paper’) and add a pdf or Phrase doc (by way of an ACF add discipline).

All that is working positive, and the paperwork are being saved in a customized folder in wp_content/uploads/papers

Nonetheless, I have to prepend the ID of the created CPT submit to the uploaded file title, eg 123-my-file-name.pdf

I do have this query posted on WordPress.org discussion board and somebody is kindly serving to me there, however first I want to determine that what I am doing is definitely potential in WordPress. I am amazed I have never discovered any snippet for this.

For these , that is my present code in features.php which leads to nothing being added to the entrance of the file title.

add_filter( 'wp_handle_upload_prefilter', 'custom_upload_filter' );
operate custom_upload_filter($file) {


   // Get the father or mother submit ID, if there's one
       if( isset($_REQUEST['p']) ) {
           $post_id = $_REQUEST['p'];
      } else {
         $post_id = false;
       }
        
    $file['name'] = $post_id . '-' . $file['name'];
    return $file;
}

I am sorry if I am breaking protocol by posting right here as effectively. But when I can set up that getting the CPT submit id is feasible on the level of making the submit and importing file I can at the very least proceed attempting to get the code to work.

Cheers,
Tracy