I'm trying to make a slider for my website, but I'm a little bit stuck right now. The thing is that I don't want to use any plugin (I prefer to try to learn how to do this, and also most plugins have extra features I don't need), and the solution I thought was to retrieve all images I have uploaded to the website.

I already know how to do that, since I did it in in another website, but the problem comes when I upload images that I don't want them to be shown in the webpage. Is there any solution for this? Something like only retrieving those images with same specific value...

Thanks in advance!

PD: this is the code I'm using for retrieving all uploaded images:

<ul id="gallery_list">
                        $args = array(
                            'post_type' => 'attachment',
                            'post_mime_type' => 'image',
                            'orderby' => 'post_date',
                            'order' => 'desc',
                            'posts_per_page' => '10',
                            'post_status'    => 'inherit'

                        $loop = new WP_Query( $args );

                        while ( $loop->have_posts() ) : $loop->the_post();

                        $image = wp_get_attachment_image_src( get_the_ID() );
                        $image_url = wp_get_attachment_url( get_the_ID() );

                        echo "<li><img src='" . $image[0] . "' alt=''></li>";


1 Answer 1


There's an infinite number of approaches to this. Here's a couple that come to mind:

1) You could easily use something like strpos() or a regular expression to see if $image[0] contains a keyword. This approach would be a little less than ideal in my opinion.

2) Add a checkbox or 'tag' field to the media manager using attachment_fields_to_save and attachment_fields_to_edit filters. Then reference that field when querying the images.

3) Create a new section within WP Admin using add_menu_page and add_submenu_page functions. Select, organize, etc.. from there. This route allows for the most customization and keeps management in a single place. In fact this paired with the second option would be the way to go in my opinion. If you're looking to learn how to create a plugin and use several hooks, functions and filters this would probably be an excellent project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.