At first you have to use readdir()
in a while loop to get all pdf files. You should look at the examples on the readdir page to know how to use it.
Inside the loop you have to add the posts with the pdf files. Normally you would use wp_insert_attachment()
to add files to your blog. But if you want a single post for each pdf which is shown on your homepage you have to use wp_insert_post()
, where the argument “file” contains the path to the file. After adding the post (but also in the loop) you have to use the id, which comes back from wp_insert_post()
, you have to add the category using wp_set_post_categories
.
I could provide you the whole code to perform this task, but in my opinion it is better to learn it by writing the code yourself. If you have further questions don’t hesitate to ask.
Related Posts:
- front end post with multiple upload images?
- View content from uploaded file in editor
- Gravity Forms – Repeatable “File Upload” field using “gform_column_input_content” filter [closed]
- How to proxy local WP uploads folder to live site
- Alow users to delete uploaded images inside backend?
- More Fields & Media Upload
- How to allow .bin files upload?
- Organizing the Media Library for Cleanup
- Limit image upload to one and disable audio, video and other document file types to upload
- what happens to existing media files when I switch to year/month directory structure format?
- Media upload finished hook
- How can I batch delete all unattached images with WP-CLI or other automated process?
- How to wp_upload_bits() to a sub-folder?
- “Add Media” only shows “Full Size” under Attachment Display Settings
- Differentiate Featured Image from Post Images upon Upload
- What might cause a POST to wp-admin/async-upload.php to return JSON >and< HTML?
- Is it possible to trigger some JavaScript when Media Popup is opened?
- What permissions does wp-content/uploads need?
- wp_handle_upload() – how to upload to a custom subdirectory within uploads
- There’s a way to scale media (images) at 50%?
- How to Reduce the Maximum Upload File Size?
- Media Uploader: get deleted files
- How can I prevent uploading bmp image?
- how to upload mp3 from url to wp media
- How to get the image url in the input box from media library?
- Add file extension to temporary file
- Post Specific Uploader
- WordPress site stuck at 1MB for max file size
- Why “Store uploads in this folder” option is not showing in Media Settings in WordPress
- Media upload via backend doen’t work after moving site
- Specified file failed upload test. Error When Uploading Image From Front-end
- Where is Featured Image code stored in WP?
- Insert into Post button is missing for certain images
- Hide upload image fields for the different media upload popups
- Thumbnails produce unwanted gray pixels on white background [closed]
- Is it safe to delete uploaded photos if Photon (Jetpack) is activated?
- Images not being generated at correct size
- Remove attachment fields from custom media uploader
- How to use MediaUpload outside of editor
- Site running slow on new server?
- update_options and unique filenames
- Add a InfoBox in the media upload window
- REST API: upload media with advanced custom fields (ACF)
- Prevent a folder from being shown within the media library
- async_upload.php 500 Error when Uploading larger files with slow internet connection and latency
- Is It Possible to Upload Certain Attachment Files To A Remote Server
- WordPress Issue : The uploaded file could not be moved to wp-content/uploads/
- After moving from complete AWS setup to a standalone WordPress Server, Media/Image Files are Broken
- Upload Button in meta box not opening library
- Duplicates and other problems in Media Library
- WordPress Media frame pre load images from ids
- How to allow logged out users to upload media?
- problem in uploading attachment to custom directory
- File Upload from Frontend
- Get all images in uploads directory and list them
- WordPress Bug on IIS ? Problem when uploading image on IIS 7
- Upload mime types for ai illustrator file
- upload_max_filesize in .user.ini Not Reflected in Media Upload
- How to resize attachement
- How does WordPress decides how many sizes of an image to create?
- Big file upload give HTTP error
- Organizing uploaded Media in permalink-based folder structure?
- Offload Media Library to other domain on a different server
- What functions of WP_Filesystem allow me to create a file with code-generated contents in a directory?
- Image upload to media library fails. Folder won’t create, database insert fail, XAMPP Windows
- Right way to download file from source to destination
- Dynamically determine the width and height of a image file to be cropped & uploaded AFTER form submission given fixed aspect ratio
- Incorrect filenames in load-scripts.php parameters
- wordpress upload permission on nginx & ubuntu
- How to change archieve frequency of the media file in uploads folder for wordpress blog
- Insert attachments from custom uploader into post (regular uploader style)
- How to download CSV from sub directory in uploads folder
- Blog suddenly can’t display .jpg
- Upload multiple files
- wordpress Do not show new image attachment in media
- 413 Request Entity Too Large nginx/1.18.0 (Ubuntu)
- Modify Maximum upload file size text in WordPress Media
- Manipulate the files uploaded via Gravity Forms before they are stored
- Replicate Media Galley Edit view in Add Media View
- Front-End Upload media with category
- Sanitizing existing media library paths and page links from foreign characters
- Cannot upload png photo files into media library. I get a ‘Could not insert post into the database’
- Do audio files impact the loading time of the website?
- File upload in WordPress
- Set default “Link CSS Class” in add media admin editor
- 45mb File Exceeds the Maximum Execution Time
- How to share media between independent blogs?
- WP Capabilities to Add Media, Use Media, But Not Edit Them
- CSS updates appear after delay [closed]
- Why isn’t my enqueuing working properly?
- What is the best way to upload a temporary & sensitive file and then delete it when done
- How do I allow family commenters to upload photos?
- Do I need FTP set up to upload files to wordpress server
- Problem uploading files, after changing domain name
- WordPress uploads directory. Featured Images storage
- Saving an upload media meta box field
- Unable to upload images using the Media Library
- Updating Media Library PDF’s in bulk
- Assign multiple categories to Media Library upload
- Update media item using wordpress rest api in python