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
- Pagination not working with custom loop
- How to Optimize WP site for millions of posts
- Differences between wpdb->get_results() and wpdb->query()
- Get Terms by IDs with IDs order
- Using WordPress public query variables
- get attachments for all posts of particular post type
- How many WordPress SQL Queries per page?
- Slow wp_enqueue_media()
- Advanced Custom Fields – Query Efficiency
- How do I sort multiples pages?
- How to display lastest post date in the homepage?
- How do I create Comma Separated list of attached image ids?
- Transient pagination not working properly
- How to tell if $query_var isset?
- Get IDs of posts currently visible on archive
- Sorting Grids with Essential Grid and Events Manger
- The use of including upgrade.php when building custom queries
- Custom query to get terms from post ids
- Get the timout value of a saved transient?
- Does meta_query work within get_posts array?
- Slow meta_query with about 4 milion record on wp_postmeta
- How to show more than 5 posts?
- WordPress Find Duplicate Post By Content
- WP Query Sort by meta value (date)
- How to optimize my query filtering out unwanted data?
- mySQL query. ORDER BY meta_key
- Remove posts from query for events whose start date has passed
- how to query multiple categories in wordpress?
- Disable the MySQL query in the main query
- Strange string in console from wpdb query
- Update slug (URL) of pending posts via phpMyAdmin
- How can I get the query that would be run for the archive page?
- Query metas (and not : query posts by metas)
- Select query for a login
- What’s wrong with my $wpdb prepare?
- where should I reset query after using get_results?
- Exclude featured image and custom field from this get_attachment query
- WordPress 3.2 query_posts and pagination, permalinks issue
- wpdb print all post meta
- Form and custom query problem
- Export Specific User data without plugin
- Query to get number of posts last week
- How to fix pagination for custom loops?
- How to write: $wpdb->update having WHERE NOT value pair in the array
- Exclude all sticky posts front page twenty twelve
- wpdb COALESCE won’t work
- get csv of users with user_meta
- Custom SQL Query passing array to WHERE p.id
- Query does not return content
- Query posts dynamic date range
- How to read the value of a WordPress $query associative array (hash) key
- Parse query filter in wordpress and relation
- Query posts based on previous query
- get posts by tag to showing in a widget
- Mysql query not working on WordPress 4.2.2
- WP_Query custom order and pagination
- i’m trying to get all my media query attachments via ajax in wordpress
- How do I get all results from my query
- get_post_meta with WP_query
- Unable to paginate a custom page query
- How properly create a blog template for wordpress?
- Is there a way to add a link directly into this media query?
- Problem on displaying the results on my query
- Improve performance of slow query
- WordPress search in modified post title
- Filter orders by modify date
- How to add url parameter to every search query in SearchWp?
- meta_query not working
- Cannot get sql request from Query object?
- WordPress query: merge meta key (number) values and sort
- Question about of query
- Is there any way to get all custom posts and all custom terms with it’s meta in few queries?
- Modify behaviour of “s” parameter in wp_query
- modifying main query to query for ranges e.g. from 1999 to 2016
- Using cron for multiple queries
- very slow wordpress query with default query
- Multilingual WordPress page – using URL to determine language?
- Pagination not working with custom loop
- Custom Query problem access the values
- Set posts per page for parent category and it’s all children
- Exclude sticky posts from query
- Pagination not working with custom loop
- Pagination not working with custom loop
- If more than 1 image show post link?
- Rewrite Query_Var URL Parameter with Slug
- How to query different categories on index?
- How to specify what kind of is_single post?
- Can’t See Media Queries with Inspect Tool [closed]
- Print data from wordpress sql query
- Can I create my own query in wordpress with traditional methods?
- Search results stuck on page 1
- How to figure out correct wp_options to have autoload=’yes’