Questions tagged [attachments]

An attachment is an image or other file uploaded through the post editor's upload utility. Attachments can be displayed on their own 'page' or template. For more information, see Using Image and File Attachments.

Filter by
Sorted by
Tagged with
0
votes
2answers
2k views

get_posts custom paging

I created a search for my site using attachments. Each attachment is in category "Pictures", so my search form looks like: <form method="get" id="searchform" action="<?php bloginfo('url'); ?>...
0
votes
2answers
944 views

Multiple if statements with else for get_the_category [closed]

I created some code to return attachment categories, that looks like: <?php // Attachment Categories $categories = get_the_category($attachment->ID); if ($categories) { ?> &...
1
vote
0answers
333 views

Open the Attachment Details popup

I'm trying to open the Attachment Details popup, but with this code it shows all the images jQuery(document).ready(function($){ $( '.attachments' ).on( 'click', '.attachment', function( event ) { ...
1
vote
1answer
278 views

Many slow queries post_type = 'attachment';

I have many slow queries. It appears when I search for a photo in a media gallery: # Time: 2017-07-02T10:04:13.180832Z # User@Host: site_234[site_234] @ localhost [] Id: 1226011 # Query_time: 2....
1
vote
1answer
363 views

add the post as canonical for attachment page wordpress

the attachment page should have canonical added to the main post on attachment page (image.php) I currently have (automatically added by All in One Seo Pack): <link rel="canonical" href="https://...
2
votes
1answer
2k views

Can i hide the attachments from media which I uploaded from front end?

I have some section where user can upload CV and profile images, I'm using the native attachment functions, $attachment_cv_id = media_handle_upload( 'candidate_cv', 0 ); if ( ! is_wp_error( $...
0
votes
1answer
325 views

Using the GetMediaLibrary() method in python-wordpress-xmlrpc.media, how to iterate over the result?

I accessed my Wordpress site's media library using the GetMediaLibrary() method of the python-wordpress-xmlrpc.media module. According to the documentation, this action should return a list of ...
1
vote
1answer
286 views

Limit Number of Taxonomy Terms (Images) Displayed

Getting some issues with taxonomy images plugin.I am trying to limit the number of taxonomy terms displayed on a page to 6. The following code is what I'm working with. It shows the term name and ...
0
votes
2answers
454 views

How to load attachment in media library for current user?

i'm using (media library) in my theme on Frontend. It's possible load only attachment of current user logged? For example, my wp user id is 55 and load only my attachment and not others by different ...
0
votes
1answer
20 views

How to Make Only Images Connected to a Post Show? Not Entire Media Collection?

When uploading an image to a post, I see ALL of the images I've uploaded. Is there a function I can use so that only the images attached to that post appear? I have no need to use images from ...
2
votes
1answer
1k views

get_attachment_id() only get id of first attached image after post update

i use the code explained here to get id of attached images to a post in a custom post type from $value that contains url of image (images already uploaded & exist in Media Library). the post ...
1
vote
1answer
980 views

How to do meta_query for attachments?

How do I do proper meta_query for attachments? This doesn't show any results $args = array( 'post_type' => 'attachment', 'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png', ...
3
votes
1answer
124 views

Get attachment from post

I would like to get the attachment from a post. I want to display a button below each of my post with a link to download them. They will be PDF. How can I do that ? Thank you
0
votes
0answers
17 views

how to add data in my custom theme from WP-Admin Panel

anybody who help me to resolve my problem. suppose i have 1 to 8 array data which contain (image, heading, description) those i want to display to my page. i want these data enter from WP admin panel ...
2
votes
1answer
175 views

Edit default image attachment size

I am building a theme and I use single.php also for attachments. The problem is that Wordpress print automatically the images with the_content() in this way: <p class="attachment"> <a ...
2
votes
1answer
111 views

Add a header before fields added with the attachment_fields_to_edit() filter

Just wondering if it's possible to add a header before fields added with the attachment_fields_to_edit() filter, just like the one before the attachment display fields. Any ideas? Thanks PHP: ...
2
votes
2answers
3k views

Check if image exists before uploading with media_sideload_image()

I'm developing a theme which will grab and upload an image when a post is published, using the following function: media_sideload_img( $url, $id, $description, 'src' ); The problem is, I often ...
3
votes
1answer
4k views

How to check if an image attachment exists before uploading

I'm trying to programatically upload images to WP checking if an image of the same name already exists. I'm doing this from within a plugin, in the admin panel via add_submenu_page(). I use a foreach(...
1
vote
1answer
72 views

Check what attached image size is used

I have registered new image size wide-image which should be wrapped inside custom div. I haven't found any wordpress function which gives me the power to check what size of the attached image is used. ...
2
votes
0answers
103 views

Perform a custom (bulk) action in media view

I wish to figure out how to add a custom action button in the media grid view ( upload.php screen) and how to perform a custom (bulk) action to the selected attachments, as shown in the screenshot ...
0
votes
1answer
269 views

Add in the url attachment loop the wp_link_pages of the post

Complete Code <?php get_header(); ?> <main id="news_posts"> <?php if (have_posts()) : ?> <?...
0
votes
0answers
358 views

Display setting 'size' not available in image settings modal

When editing a post in WP-Admin, I'm missing the size option in the display settings of attached images. In this screenshot, the setting is available: However, this is, what it looks in my page (in ...
4
votes
2answers
1k views

Count the number of images uploded on the website

I mention "full website" because I don't need the number of attachments on one post (as answered in many questions). I basically need a function that returns the number of uploaded images (attached ...
1
vote
0answers
482 views

hook wp_generate_attachment_metadata does not read all the attachments

I am using GD libraries in order to modify the uploaded attachment so I can have always the crop at the same squared dimensions with white stripes top/bottom or left/right if the image is not squared ...
1
vote
1answer
563 views

Auto delete attachments that are older than x days

Is there a method to auto delete attachments that are older than x days? cause every now and then I end up having over 10million images and database grows so big that it slows down site due to limited ...
1
vote
0answers
29 views

How to filter a post in the Tag Cloud widget, using tags of a media library image attached to the post?

I hope my question is rather common. There are some posts. These posts have images as attachments. These images are stored in the Media Library and have tags based on custom taxonomy. Obviously, if ...
0
votes
1answer
78 views

Is There A WordPress Hook for Accessing Attachments for A Particular Page?

I'm writing a site with a category that's used for formatting specific types of reports. The user logs in, and writes the report as a blog entry. When they select the category, the report is ...
1
vote
1answer
3k views

woocommerce_email_attachments filter arguments [closed]

I’m trying to generate PDF attachment for new order emails in WooCommerce and this is what I found: add_filter('woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email'); function ...
0
votes
1answer
738 views

Get “Image CSS Class” value from the Advanced Options section

By default, WordPress allows to add an extra class to the image via Advanced Options section: https://cloudup.com/cBR2yxukXm9 If I know the image (attachment) ID then how can I get this value? I ...
1
vote
2answers
121 views

Making audio playlist by getting page's parent's ID

So right now the site automatically creates pages when a post is updated. I want this page to include an audio playlist. So what I do, is simply add the shortcode: [playlist]. Then, when the audio ...
12
votes
3answers
21k views

Programmatically adding images to media library

I am trying to programmatically add multiple images to media library, I uploaded the images to wp-content/uploads, now I try to use wp_insert_attachement. Here's the code, however it's not working as ...
2
votes
1answer
2k views

How to save custom fields for attachments

I have added a custom field "Buy Now" link on media edit page but I am not able to save that data like other post types. Is there any other hook which is triggered after add/edit/update media/...
0
votes
1answer
438 views

How to hide / remove attachment “alt” or “caption” field in Admin?

Until WP 3.6 it was possible to remove the "alt" field (and also the "caption" field) before showing a post of type "attachment" through attachment_fields_to_edit hook. As you can see also here (user ...
2
votes
1answer
627 views

Get url from file uploaded in Media Library

I have a file called Portfolio.zip in my Media Library which will always have this name. Now in my page template I need the url to this file. I can achieve this via his id : wp_get_attachment_url( $...
0
votes
2answers
1k views

How can I make an attachment page for pdf uploads?

I have an attachment page for post images, so that when I click on the thumbnail (on the front end) it takes the user to the attachment page for that image, how would I do the same for pdf files, so ...
0
votes
2answers
107 views

How do I fit a function inside an opening and closing do_shortcode

How do I fit a function inside an opening and closing shortcode. I have this function that displays the post's pdf attachment url $file= get_post_meta( $post->ID, 'teacher-resume-upload' ); if ( ...
0
votes
0answers
474 views

“Could not write file” error in wp_upload_bits function

I'm trying to scrape images from the web and upload the binary files by using wp_upload_bits (https://codex.wordpress.org/Function_Reference/wp_upload_bits) This works fine for about 95% of the ...
0
votes
1answer
49 views

How get all media from a posts category by db?

I need to obtain all media data from wp_posts table that are embeded in a specific post category. In other words, I need all media data from elementes incrusted in a list of posts elements. But I ...
0
votes
1answer
17 views

Find out last 7 days of upload images, last week uploaded image from Gallery and display them in different pages

In my Gallery, I have many pictures which are uploaded by the visitors of the site. I want to show them in pages based on when the images were uploaded. E.g. 'Last 7 days', 'Last month', etc.
0
votes
3answers
1k views

Post Title to link to a PDF

I want to link a Post Title to the PDF. I feel my solution is somewhere in wp_get_attachment_url() but I can't figure out how. Also, I'd like my pdf to be located in ../wp-content/uploads/year/month/...
1
vote
1answer
21 views

Deleting images in array

Is it possible to delete all the images with ID's given in input field? I have field: <input type="hidden" id="deleteimg" value="3008,3009,3010,3011,3012" class="something"> I'm getting field ...
0
votes
1answer
236 views

How to delete attachments associated with custom field type when post property changes? [closed]

I have a WordPress site with cars that have a custom field named "deal type". That field can be either "selling" or "sold". The "selling" cars have a custom field named "main picture", with a single ...
1
vote
2answers
2k views

How do i upload an image and return the image id?

I need to import images from an url and return the image id is it possible to make a function like this? <?php $link = 'https://mosaic01.ztat.net/vgs/media/pdp-zoom/NI/11/3D/03/4D/11/...
1
vote
1answer
581 views

get_attached_media() on author page not working

I have a very annoying and simple problem. I can use get_attached_media() on a taxonomy page to get the attached media of a custom post. function author_loop() { $post = get_the_ID(); // ...
2
votes
2answers
6k views

How to get custom field image url of specific size

I have a "cmb2" custom field with type->file. and i use it to upload images. If i use: echo get_post_meta( $post->ID, '_pf_photo1', 'medium' ); i get the url of the full image (not the medium ...
0
votes
1answer
607 views

Uploaded images not showing properly using wordpress

I need to insert post programatically in wordpress.. I finished to insert title and content.. But image is not uploaded and attached.. Can you suggest me.. $post_id = wp_insert_post( array( ...
0
votes
2answers
177 views

Retrieving post meta array (attachment)

I have a post meta for image uploads which allows a maximum of 5 files. The data is stored in like this: a:5:{i:0;s:3:"694";i:1;s:3:"694";i:2;s:3:"697";i:3;s:3:"695";i:4;s:3:"696";} The problem is, ...
1
vote
0answers
57 views

Hierarchy and access control for Custom Post Types (CPT)

I want to build a up a new system based on WordPress to manage my content. I am new to WordPress and have written previous systems from scratch using PHP/mySQL. Unfortunately it's not a simple blog ...
0
votes
1answer
146 views

Update Cateogory Taxonomy Count for Attachment Post Type

For the attachment post type, I added taxonomy 'Categories'. After an import the categories have the incorrect count of attachment(s). This link has a script that can be ran to fix the issue, but it ...
0
votes
1answer
42 views

How to restrict users to only access their own media files in wordpress

<?php $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' =>'image') ); foreach ( $attachments as $attachment_id => $...

1 2 3
4
5
19