Automatically deactivate link for attachments

With markup embedded into the content there is no less tricky way than regex to do it, save perhaps a markup parser like SimpleHTMLDom function remove_image_link_102512($content) { $pattern = ‘|<a.*?href=”https://wordpress.stackexchange.com/questions/102512/(.*)”.*>?(<img.*?/?>)(?:</a>)?|’; $content = preg_replace($pattern,’$2′,$content); return $content; } add_filter(‘the_content’,’remove_image_link_102512′); As with all regex + markup solutions, I’d test that thoroughly. Of course, as no saved data is … Read more

Remove attachment from database

Just use a custom $wpdb query, something like function remove_all_attachments() { global $wpdb; $ids = $wpdb->get_col(“SELECT ID FROM $wpdb->posts WHERE post_type=”attachment””); if ( empty($ids) ) return; $remove = implode(‘,’, $ids); // remove post meta $wpdb->query(“DELETE FROM $wpdb->postmeta WHERE post_id IN ({$remove})”); // remove posts $wpdb->query(“DELETE FROM $wpdb->posts WHERE ID = IN ({$remove})”); } After that … Read more

Unable to get wp_get_attachment_url to show

That’s not going to work, instead just use wp_get_attachment_image_src , it takes a size parameter. // get the $attachment_id $attach_stuff = wp_get_attachment_image_src( $attachment_id, ‘full’); var_dump($attach_stuff); You will be returned an array fo values to work with: [0] => url [1] => width [2] => height [3] => boolean: true if $url is a resized image, … Read more

How can i catch (with get_posts) attachment file (pdf, images) from a post when i have only inserted it from media library and it isn’t upload for it?

When you upload a media from a post, the post_parent attribute is setted to the post ID you are uploading from. Not so when you simple insert a post from the library: in that case if the media was already attached to a post, its post_parent is already setted, and once a media can have … Read more

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