Get post id while uploading image

WCMp Advanced Frontend Manager

Get post id while uploading image Open

Viewing 6 reply threads
  • Author
    • #138058
      Tim Kerremans

      Hi there,

      I’m trying to create a function where I rename the image while it is uploading. I want to name the image file as the post id. The code below works when uploading images to posts in WP Admin, however, when I try to recreate this on edit-product page it is not returning the ID, it gives NULL.

      function handle_uploadedimage($arr) {

      $current_post_id = $_REQUEST[‘post_id’];
      $ext = pathinfo($arr[‘name’], PATHINFO_EXTENSION);
      $arr[‘name’] = $current_post_id .’.’.$ext;

      return $arr;
      add_filter(‘wp_handle_upload_prefilter’, ‘handle_uploadedimage’, 1, 1);

    • #138092

      Using above code we get the post id from the product image upload page.
      Kindly check out the video – https://www.awesomescreenshot.com/video/9542745?key=d60eeef33f23079dfd1ccdaba20f77d6

      If you have any other issue kindly share a video of the issue.


    • #138095
      Tim Kerremans


      Like I said it is working on WP Admin, but it is not working on the edit-product page from Advanced Frontend Manager plugin. (This is where the vendors upload images)

      I think that is clear enough for you to test it, or do you need a video?

    • #138098
      Tim Kerremans

      It would be even better if the title of the product image is updated to the product ID when the product is submitted on the edit-product page. Maybe this is also easier to achieve?

      So when vendor cliks on SUBMIT on edit product page -> Image title has to be change to Product ID

    • #138184

      WCMp does not save product as a post till the product is save.
      As per your requirement you have add custom code.

      Kindly use below hook.

      do_action( 'wcmp_process_product_meta_' . $product_type, $post_id, $_POST );


    • #138185
      Tim Kerremans


      Not sure about the default flow but in my case the the product is created and saved as draft once vendors are on edit-product page. I can see this as the products can be found in products -> drafts. There I can see in the URL that they do have a post ID assigned to them. Therefore I thought that it should be possible to grab the post id on the edit-product page.

      If not, how should I use the hook? Add to the existing function or create a seperate function?

    • #138212

      @Tim Kerremans, as you can understand the flow is not supported by default and we presume you have done some custom code to achieve this.

      So I would request you to contact the developer who has created this custom flow for you, as they know the coding you have applied and can assist you further on this. i.e. how to use hook and what code to apply.

Viewing 6 reply threads

Please LOGIN to reply to this topic

Buy all Marketplace addons together!!

Check Slashed Price