Articles of attachments

Prevent attachment from being deleted

In WordPress admin media library page (upload.php) I’d like to do some checking on delete_attachment action. I want my custom function to fire before attachment’s being deleted. In this function I want to check for it’s relations with another objects in database. And delete it only if there are no relations at all. I use […]

i'm trying to get all my media query attachments via ajax in wordpress

i’m trying to load all my media files via ajax: $.ajax({ url: ‘/wp-admin/admin-ajax.php’, type: ‘post’, data: { ‘action’: ‘query-attachments’, ‘post_id’: 0, ‘query[orderby]’: ‘date’, ‘query[order]’: ‘DESC’, ‘query[posts_per_page]’: -1, ‘query[paged]’: 1 }, }); as you can see i’m trying to get ALL my media files: ‘query[posts_per_page]’: -1, in my template, i’m trying to get and display all […]

All attachment pages give 404

I have a major issue with wordpress on my new website. Anytime I upload a new media, its attachment page gives me a 404. My permalink structure is the following: baseurl + /%category%/%year%/%monthnum%/%day%/%postname%/ I have hundreds of media (imported from old website) and they all give a 404. I can access the media directly but […]

wp_query get attachments in larger size

I’m using wp_query to get all attachments, and it works, but I wonder how could I get attachments in full size because this query returns images in medium. <?php $args = array(‘post_status’ => ‘inherit’, ‘post_type’ => ‘attachment’, ‘posts_per_page’ => 5 ); $wp_query = new WP_Query($args); while (have_posts() ) : the_post(); ?> <article id=”post-<?php the_ID(); ?>” […]

Creating attachments archive in tags and categories

Per this question (How to create an attachments archive with working pagination?), I’ve been using the following function to have archive pages display attachments as well as pages and posts. It was working for the preexisting tag and category archive pages, but it stopped working a few weeks ago (possibly due to a WordPress update, […]

Change permalink to attachment

Hello i found this code and I modified a litle, but i have a problem with it. I want the link of the attachment page to be something like this [post-permalink]//[postid] 1234/ .. /1253/ I tried this, the URL is like I want to be but gives me a 404 error: function wpd_attachment_link( $link, $post_id […]

get_post orderby not working in plugin

Please take a look at the loops below, I’m having issues trying to order the attachment by title, name, and modified. <?php foreach ($instance[‘data’] as $id) : $args = array( ‘include’ => $id, ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘post_status’ => ‘any’, ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, ); $data_attach = get_posts($args); foreach ($data_attach as […]

Upload multiple image with media_handle_upload with multiple file field

This question already has an answer here: Upload Multiple Files With media_handle_upload 3 answers

Show last 12 uploaded images on home page, but only from posts

I want to show the last 12 images that were published with articles on my front page. This is the code to get the latest 12 uploaded images, but i want to show only the ones attached to a post (single). Any idea? <?php $args = array( ‘post_type’ => ‘attachment’, ‘numberposts’ => 12, ‘post_status’ => […]

How do I intercept and modify the functionality of wp_get_attachment_image()?

I have a site I’m building in wordpress that has ~80GB of high resolution images, and it’s exceeding my managed host’s storage space. My plan is to move all the images to S3, but I noticed that wp_get_attachment_image() automatically prefixes the src with /wp-content/uploads instead of respecting the path stored in the database. Is there […]