Skip to content

Instantly share code, notes, and snippets.

Created March 21, 2017 05:01
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 anonymous/a79e1223d5e6dd1f89161097a3e5a2b8 to your computer and use it in GitHub Desktop.
Save anonymous/a79e1223d5e6dd1f89161097a3e5a2b8 to your computer and use it in GitHub Desktop.
function education_hub_get_featured_content_details( $input ) {
$featured_content_type = education_hub_get_option( 'featured_content_type' );
$featured_content_number = education_hub_get_option( 'featured_content_number' );
switch ( $featured_content_type ) {
case 'featured-page':
$ids = array();
for ( $i = 1; $i <= $featured_content_number ; $i++ ) {
$id = education_hub_get_option( 'featured_content_page_' . $i );
if ( ! empty( $id ) ) {
$ids[] = absint( $id );
}
}
// Bail if no valid pages are selected.
if ( empty( $ids ) ) {
return $input;
}
$qargs = array(
'posts_per_page' => esc_attr( $featured_content_number ),
'no_found_rows' => true,
'orderby' => 'post__in',
'post_type' => 'page',
'post__in' => $ids,
);
// Fetch posts.
$all_posts = get_posts( $qargs );
$contents = array();
if ( ! empty( $all_posts ) ) {
$cnt = 0;
foreach ( $all_posts as $key => $post ) {
$image_array = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'education-hub-thumb' );
$contents[ $cnt ]['images'] = $image_array;
$contents[ $cnt ]['title'] = esc_html( $post->post_title );
$contents[ $cnt ]['url'] = esc_url( get_permalink( $post->ID ) );
$contents[ $cnt ]['excerpt'] = education_hub_the_excerpt( apply_filters( 'education_hub_filter_featured_content_excerpt_length', 10), $post );
$cnt++;
}
}
if ( ! empty( $contents ) ) {
$input = $contents;
}
break;
default:
break;
}
return $input;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment