Is there a way to display the the most recent images added to any gallery field on the site on the homepage?
If I had for example an “Artist” post type and within that post type was a gallery custom field to add a portfolio for that artists work.
If I had 100’s of artists and I wanted to just display a collection of the latest uploaded images to artist’s galleries on the homepage, how would I do it?
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
//* 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() ) :
while( $the_query->have_posts() ) :
$images = get_field('gallery');
if( $images ):
foreach( $images as $image ):
echo '<a href=';
echo '<img src=';
echo ' alt=';
echo ' />';
//* Restore original Post Data
//* 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)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users