0

I'm new to wordpress. I was making a theme with articles in a Gallery like style with swiper

enter image description here

And I wanted add video (from vimeo/youtube ...) I've actually copied a php code for a Image only gallery

    $args = array(
    'numberposts' => -1, // Using -1 loads all posts
    'orderby' => 'menu_order', // This ensures images are in the order set in the page media manager
    'order'=> 'ASC',
    'post_mime_type' => 'image', // Make sure it doesn't pull other resources, like videos
    'post_parent' => $post->ID, // Important part - ensures the associated images are loaded
    'post_status' => null,
    'post_type' => 'attachment'
);

And I wanted to know how to add video there. I tried adding 'post_mime_type' => 'image', 'video', 'iframe', but it didn't do anything.

Any suggestion ?

Thanks in advance :)

2
  • See this. Anyway, it's off-topic here.
    – Max Yudin
    Jul 5, 2017 at 12:59
  • I think you did not understand my problem. Maybe my question was not well explained. Thus, my problem doesn't have any link with swiper. I just wanted to add more content to the gallery than just "image".
    – Felix Jely
    Jul 5, 2017 at 13:27

1 Answer 1

0

The problem is that image is not a proper mime type. You can see a list of mime-types here - so based off the linked list we need to pass an array of what we need:

$supported_mimes = array(
    'image/jpeg', 'image/gif', 'image/png',
    'video/avi', 'video/x-flv', 'video/mp4', 'video/ogg', 'video/webm',

);

$args = array(
    'numberposts'       => -1, // Using -1 loads all posts
    'orderby'           => 'menu_order', // This ensures images are in the order set in the page media manager
    'order'             => 'ASC',
    'post_mime_type'    => $supported_mimes
    'post_parent'       => $post->ID, // Important part - ensures the associated images are loaded
    'post_status'       => null,
    'post_type'         => 'attachment'
);

I think the bigger problem is enabling WordPress to allow you to create a gallery with both images and videos but as far as this goes, this is just pulling media uploaded to that post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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