EDIT: I didn’t read your code properly, sorry!
You’re using get posts which will only retrieve posts. To get all the images from the media library you’ll need to use WP_query.
$query_images_args = array(
'post_type' => 'attachment',
'post_mime_type' =>'image',
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image) {
$images[]= wp_get_attachment_url( $image->ID );
}
This code will put all the URLs of images from the media library into the $images array.
ref: https://wpeden.com/tipsntuts/list-all-images-at-media-gallery-in-your-wordpress-site/
Related Posts:
- Get all image from single page using this query
- search through post-type attachments titles
- List WordPress Post and Related Attachments outside of a post page
- Query Post interferes with Pagination
- My custom pagination not displaying
- Pagination adds search query (again)
- Attachment page tag queries & posts not found
- WordPress: paginating array using a foreach
- “Page Not Found” with multiple last pages of query
- How to fix pagination for custom loops?
- How to display SQL query that ran in query?
- Pagination not working with custom loop
- How can I create a meta_query with an array as meta_field?
- Query multiple meta key values?
- How to Optimize WP site for millions of posts
- How to get comments by post ID?
- WordPress Paginate $wpdb->get_results
- Differences between wpdb->get_results() and wpdb->query()
- Is there a way of increasing the speed of this query?
- How can I query all users who registered today?
- Get Terms by IDs with IDs order
- Reversing the order of posts AFTER the query is performed
- How to paginate wordpress [gallery] shortcode?
- what are the numbers between curly brackets in search query
- simple sql query on wp_postmeta very slow
- Using WordPress public query variables
- How to Use Wildcards in $wpdb Queries Using $wpdb->get_results & $wpdb->prepare?
- When/why does ‘$query->get( ‘tax_query’ );’ return empty?
- get attachments for all posts of particular post type
- How can I make wp-pagenavi work on a custom query built upon a form submission? [closed]
- How to get link and title of next and previous post on single page
- Create pagination and order according to alphabet
- wpdb get posts by taxonomy SQL
- How to List Events by Year and Month Using Advanced Custom Fields?
- Is there any difference between hooks posts_where with posts_join and posts_search performance wise?
- Custom WP_Query order by post_meta and (author) user_meta
- wordpress query – orderby child post date
- Get wp_get_attachment_url outside of loop
- How many WordPress SQL Queries per page?
- How to paginate attachments in a secondary query as gallery?
- How to display Section for certain time
- Add multiple value to a query variable in WordPress
- Search custom post type by meta data
- Custom query_var causes displaying posts archive on front page
- Slow wp_enqueue_media()
- Multipart/formatted MySQL query problem
- What is the most efficient way of implementing a favorite post system?
- Remove [gallery] shortcode altogether
- Compare two numeric custom fields
- wp_dropdown_categories with multiple select
- Advanced Custom Fields – Query Efficiency
- Why does get_the_time(‘F j’) return November 30 for all posts?
- Disable slow media queries?
- Query by one meta_key and sort by another (possibly NULL value)
- How to tune search argument in WP_Query to show only exactly the same results?
- Custom query filter not working on woocommerce category page
- How to delete a transient on post/page publish?
- Very slow query
- query multiple taxonomy and show post count
- Search Terms – Querying on either description__like OR name__like in the same Term Query?
- Query & Sort Comments by custom comment meta
- How to get my loop to pull posts into three columns
- How do I sort multiples pages?
- How to display lastest post date in the homepage?
- Add and in the header while looping over custom query in page template
- Custom $wpdb Query for Custom Post Type by Category
- Limit number of pages in pagination
- Get a user’s most recent post title
- Categories and products in random order
- Custom Permalinks Break Search Pagination
- add_query_arg() XSS Vulnerability
- Count user posts by user ID, Post type and Post status
- Can’t pass table to $wpdb->prepare
- Query set using tax_query with relation ‘OR’ modifies category object?
- $query->query_var[‘post_type’] not set for pages
- is_archive() doesn’t work on public query var archive pages?
- How do I create Comma Separated list of attached image ids?
- How to extract all ID variables from a query string?
- When add_query_arg() is necessary?
- Different Main Navigation per category
- How to get category link without a database query
- Insert html after certain amount of posts?
- wp remove query
- Show recent products first but “sold out last” in query
- pagination in author.php template returns 404 error
- Transient pagination not working properly
- WordPress creating excessive joins on meta_query with search
- How to display liked posts of current user in wordpress?
- get_query_var(‘paged’) giving same result
- Filter query posts by the count of metas for a meta key
- How to tell if $query_var isset?
- Show All Posts Insert Edit Link
- Custom Post Types, Page Templates and Pagination. Why do I get a 404 Error?
- $wpdb->get_var not returning a result
- How to count get_users query?
- Date query year and month OR just year
- cron job to auto delete posts of a specific post type older than x days
- Possible to get posts from multiple meta keys/values in a single query?
- Are database queries created using WordPress filters protected from SQL injection?
- Get IDs of posts currently visible on archive