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
- Trying to Add Paging to Single Post Page
- How to fix pagination for custom loops?
- simple sql query on wp_postmeta very slow
- Add multiple value to a query variable in WordPress
- wp_dropdown_categories with multiple select
- 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 get my loop to pull posts into three columns
- Add and in the header while looping over custom query in page template
- Custom $wpdb Query for Custom Post Type by Category
- Can’t pass table to $wpdb->prepare
- WordPress creating excessive joins on meta_query with search
- How to display liked posts of current user in wordpress?
- Date query year and month OR just year
- Are database queries created using WordPress filters protected from SQL injection?
- add spans and characters into paginate_links
- get post id using the $query_vars variable
- Is there a conditional tag for latest post or do i need a query?
- get_posts() loop returns the same the_title() for each post
- Huge amount of queries on my site
- How to check current user in meta value array in WP_Query meta_query
- How select a specific query when setting offset?
- Change media attachment author via mysql query
- Should $found_posts be returned as string in ‘found_posts’ filter hook?
- Get post according to current taxonomy
- Temporarily storing main search result
- Help with MySQL to $WPDB query
- Alter query with posts_clauses to retrieve NULL values last
- sql select query in wordpress ‘page’ [closed]
- wpdb->term_taxonomy count posts from both published and private posts?
- Group custom post listing in admin section
- problem with sql query in wordpress plugin
- Attempt to improve WP search, can someone check my SQL query?
- Multiple Category Query
- list all categories that have a certain word in title
- Passing parameters to a static front page
- wp_list_pages() refuses to output posts
- Can’t seem to do combined query AND sort?
- sort query results by newest
- How to reset usual $query on search page to push custom $wpdb query there?
- get_posts showing only 5 posts. (nopaging and posts_per_page -1 not working)
- Order by meta value pro first then meta value free in my search function
- How to get category/tag in URL for Pagination links?
- Order posts by date, but also give priority for a specific term
- How to delete all posts, categories and tags from WordPress database
- Ideas how to search & replace post_content when string contains a newline?
- Break up posts per page in two sections
- Query the WordPress database to get data together with replaced information
- $wpdb->prepare affecting the query?
- WordPress SQL search, how to handle SQL Injection?
- Pagination issue with tag.php
- Query for Custom Post Type UI Does Not Loop All the Post
- Updating with $qpdb->query() always returns 0 rows affected
- wpdb query with dynamic column name?
- How do you display the number of a post in a query?
- How to manage a particular “order by” for get_search_query()?
- Query to view scheduled or draft post
- I am officially missing something about transient posts
- Can I paginate this get_attachment query?
- How to add a Variable to post query
- get products by custom date variable
- Sort a list of a CPT ( job) if a meta is empty
- How to sort by two meta keys in admin area?
- Custom query pagination with php parameter as arg problem
- PHP Fatal error: Uncaught Error: Call to a member function insert() on null
- Nested select statements not working
- Restore WordPress Backup Locally?
- Trouble migrating custom post types from non-wordpress cms
- Fastest and most efficient SQL query to check if UID exists
- Counting And Monitoring How Much Queries My Script Used
- Get posts associated with media attachment
- Run an update query in a function
- Add generic page to WP_Query
- Advanced Custom Fields Query with Different Values of the Same Key
- No results for taxonomy archive page
- search.php is not generating the right results
- Slow query when joining wp_posts with a lookup-table?
- Filter the feed page post limit
- Show links to child pages on both parent AND child pages
- Mysql query and odd results
- Using wp_list_table how to trigger update function “inline”?
- Filter multiple different main queries on custom pages
- Loop issues when creating custom query for media uploader
- Modify Global Posts Plugin
- SQL: Search query to get attachments only of those parents which are published
- How to reference same column name but different table in custom db query
- Retrieving custom field array value through db query
- WP_Query older new links navigation?
- How to get one result using wpdb class?
- Delete query won’t run
- Modify a query using both a text field and a true/false AFC field
- Can I make a Heading block above a query loop block disappear when that query loop has no results?