0

My current way of getting the images for sliders is by using the following code that works perfectly:

$args = array(
    'post_type' => 'attachment',
    'sort_order' => 'ASC',
    'sort_column' => 'menu_order',
);

$attachments = get_posts($args);

if ($attachments) {
    $i = 0;
    foreach ($attachments as $attachment) {
        $title = $attachment->post_title; // title
        if ( strpos($title, 'slide') !== false ) {
            $img = wp_get_attachment_url($attachment->ID); 
            $caption = $attachment->post_excerpt;
        //...

But now I have realized for later stuff I will need to categorize images so I registered categories in functions.php and categorised them. Now I am unsure though how to change the code to look for images in the slides category.

I have been working through the codex and found wp_list_categories() do I need to use that at all or is there a parameter in args that I can set?

Any links or help are great. I will continue to look through the codex and let you guys know if I come up with anything.

Edit: Also I have seen some questions on here trying to find attachments of posts. I am not trying to do that. I want to get images directly from the media gallery.

1 Answer 1

0
'category_name' => 'slides',

that appears to be all that is needed. Not sure if there is a more appropriate way but it is working.

The Wordpress documentation has to be some of the worst formatted and organised out of any major software documentation. Plenty of information just so hard to navigate.

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.