Support

Account

Forum Replies Created

  • This reply has been marked as private.
  • I have this exact same request. I have setup the following with wp_query and it does display the artist’s gallery images. However, it does not sort them by the gallery custom field across all posts. Instead it sorts them by the CPT post first and then sorts the photos in the order you have them in the gallery field.

    //* Define a custom function that queries the database for your posts
    function display_artist_post_images(){
    
    		//* Limit query to posts with "post type" set to "artist"
    		$queryArgs = array(
    			'post_type' => 'artist',
    			'orderby' => 'date',
    			'order' => 'ASC'
    		);
    
    		//* The query
    		$the_query = new WP_Query( $queryArgs );
    
    		//* The loop
    		if( $the_query->have_posts() ) :
    			echo '<ul>';
    			while( $the_query->have_posts() ) :
    				$the_query->the_post();
    				$images = get_field('gallery');
    				if( $images ):
    						foreach( $images as $image ):
    							echo '<li>';
    								echo '<a href=';
    								echo $image['url'];
    								echo '>';
    									echo '<img src=';
    									echo $image['sizes']['thumbnail'];
    									echo ' alt=';
    									echo $image['alt'];
    									echo ' />';
    								echo '</a>';
    								echo '<p>';
    								echo $image['caption'];
    								echo '</p>';
    							echo '</li>';
    						endforeach;
    				endif;
    			endwhile;
    			echo '</ul>';
    		endif;
    
    		//* Restore original Post Data
    		wp_reset_postdata();
    	}
    	//* Add your custom function to the site using WP's "add_action" function with a Genesis hook.
    	add_action( 'genesis_entry_content', 'display_artist_post_images' );
Viewing 3 posts - 1 through 3 (of 3 total)