• Hello there,

    I am trying to get the number of attachments of the created post with this:

    function fu_after_create_post( $post_id ) {
    
      // Get the ID of the outreach idea
       $current_post_id = $_POST['current_post_id'];
    
       // get the number of attachments created
       $attachments_number = get_posts( array( 'post_type' => 'attachment','post_mime_type' => 'image', 'post_parent' => $post_id, 'post_status'=>'published',  'numberposts' => -1 ) );
       $count = count( $attachments_number );
    
       //Get number of previous attachments
       $previous_photos_number = $_POST['photos_numbers'];
    
       //New photos number
       $total_photos_number = $count + $previous_photos_number;
    
       //Update the post meta photos number
       update_post_meta($current_post_id, 'wpcf-total-photos', $total_photos_number);
    
    }

    But somehow this part is not working to count the number of attachments to the created post. Any ideas why? Thx a lot!

    $attachments_number = get_posts( array( 'post_type' => 'attachment','post_mime_type' => 'image', 'post_parent' => $post_id, 'post_status'=>'published',  'numberposts' => -1 ) );
       $count = count( $attachments_number );

    Thx for your help and an amazing plugin!

    http://wordpress.org/extend/plugins/frontend-uploader/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Rinat

    (@rinatkhaziev)

    Hey,

    Probably
    'post_status'=>'published', is the problem. Try to change it to private, because all the attachments get it when uploaded.

    Let me know if this helped.

    Thread Starter revolutionfrance

    (@revolutionfrance)

    Hello! thx for your answer, but in my settings the post is set as published on submission, so that shouldn’t be the reason. Still I tried with “private”, but the count still returns 0. Strange

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get number of attachments’ is closed to new replies.