Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created June 1, 2016 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/7dc08f6045dd15cf73fc561c558dcddf to your computer and use it in GitHub Desktop.
Save billerickson/7dc08f6045dd15cf73fc561c558dcddf to your computer and use it in GitHub Desktop.
<?php
/**
* Default to most recent image
*
* @author Bill Erickson
* @link http://www.billerickson.net/code/default-to-most-recent-image
*
* @param array $defaults
* @param array $args
* @return array $defaults
*/
function ea_default_to_most_recent_image( $defaults, $args ) {
$image_ids = array_keys(
get_children(
array(
'post_parent' => isset( $args['post_id'] ) ? $args['post_id'] : get_the_ID(),
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC',
)
)
);
$defaults['num'] = key( array_slice( $image_ids, -1, 1, TRUE ) );
return $defaults;
}
add_filter( 'genesis_get_image_default_args', 'ea_default_to_most_recent_image', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment