Delete attachment with post

This is the right hook to do this: add_action(‘before_delete_post’, ‘delete_post_attachments’); function delete_post_attachments($post_id){ global $wpdb; global $post_type; if (!$post_type == ‘bkroadkill’) return; $args = array( ‘post_type’ => ‘attachment’, ‘post_status’ => ‘any’, ‘posts_per_page’ => -1, ‘post_parent’ => $post_id ); $attachments = new WP_Query($args); $attachment_ids = array(); if($attachments->have_posts()) : while($attachments->have_posts()) : $attachments->the_post(); $attachment_ids[] = get_the_id(); endwhile; endif; wp_reset_postdata(); … Read more

Importing Attachments with No Extension

With no native solution popping up here, I ended up writing a script that Parsed my the XML import file I had and identified problem attachments Manually download those attachments with a file extension Upload those images to a new web server Alter the appropriate link and wp:attachment_url nodes to point to the new URLs … Read more

How to remove attachments from main query via pre_get_posts?

Rather than using pre_get_posts hook, you could try a better approach which will work perfectly with parse_request hook. The code – add_action( ‘parse_request’, ‘my_cpt_parse_request’, 11, 2 ); function my_cpt_parse_request( $wp ) { if( isset($wp->request) && !is_admin() ) { $requests = explode(“https://wordpress.stackexchange.com/”, $wp->request); $request_amount = count($requests); $post_name = array_shift( $requests ); // if an attachment has … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)