show image gallery in archives or category page

i want to show image gallery in archives.php or category.php. The featured image and text content is showing but not image gallery. Below is the code inside category.php. I have tested to show one post from category 'blog'.

$args = array(
        'post_type' = 'post',
        'post_status' = 'any',
        'cat'=3,
             'meta_query'=
       array('relation'='AND',
         array(
        'key'='intro_post','value'='intro','type'='CHAR','compare'='LIKE'
        )
       )
   );
   $arr_posts = new WP_Query( $args );?
    ?php  if (  $arr_posts-have_posts() ) : ?
             ?php  while ( $arr_posts-have_posts() ) : $arr_posts-the_post(); ?
                  div class="entry-content"
                        ?php if (has_post_thumbnail()): ?
                        figure
                        ?php the_post_thumbnail('full');?
                        /figure
                       ?php endif; ?
        ?php the_content(); ?

        /div!-- .entry-content --
                 ?php  endwhile; ?
          ?php else : ?
               ?php get_template_part( 'template-parts/content', 'none' ); ?
          ?php endif; 
           wp_reset_query();

Topic wp-query categories gallery posts archives Wordpress

Category Web


I fixed it. I set query 'post_type' to 'attachment' and 'post' in pre_get_posts hook. So now image galleries are showing in archive or category. 


If posts have post_format is gallery, you can get all gallaries by used: get_post_gallery_images(get_the_ID()); See more: https://pippinsplugins.com/retrieving-image-urls-of-galleries/

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.