Get number of attachments
-
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!
https://www.ads-software.com/extend/plugins/frontend-uploader/
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Get number of attachments’ is closed to new replies.