'-1', 'orderby' => 'date', 'order' => 'DESC', 'id' => 0, 'category' => 0 ); $args = wp_parse_args( $args, $defaults ); // Allow child themes/plugins to filter here. $args = apply_filters( 'woothemes_get_timeline_data_args', $args ); // The Query Arguments. $query_args = array(); $query_args['post_type'] = 'post'; $query_args['numberposts'] = $args['limit']; $query_args['orderby'] = $args['orderby']; $query_args['order'] = $args['order']; $query_args['suppress_filters'] = 0; if ( is_numeric( $args['id'] ) && ( intval( $args['id'] ) > 0 ) ) { $query_args['p'] = intval( $args['id'] ); } // Whitelist checks. if ( ! in_array( $query_args['orderby'], array( 'none', 'ID', 'author', 'title', 'date', 'modified', 'parent', 'rand', 'comment_count', 'menu_order', 'meta_value', 'meta_value_num' ) ) ) { $query_args['orderby'] = 'date'; } if ( ! in_array( $query_args['order'], array( 'ASC', 'DESC' ) ) ) { $query_args['order'] = 'DESC'; } if ( ! in_array( $query_args['post_type'], get_post_types() ) ) { $query_args['post_type'] = 'post'; } $tax_field_type = ''; // If the category ID is specified. if ( is_numeric( $args['category'] ) && 0 < intval( $args['category'] ) ) { $tax_field_type = 'id'; } // If the category slug is specified. if ( ! is_numeric( $args['category'] ) && is_string( $args['category'] ) ) { $tax_field_type = 'slug'; } // Setup the taxonomy query. if ( '' != $tax_field_type ) { $term = $args['category']; if ( is_string( $term ) ) { $term = esc_html( $term ); } else { $term = intval( $term ); } $query_args['tax_query'] = array( array( 'taxonomy' => 'category', 'field' => $tax_field_type, 'terms' => array( $term ) ) ); } // The Query. $query = get_posts( $query_args ); // The Display. if ( ! is_wp_error( $query ) && is_array( $query ) && count( $query ) > 0 ) { foreach ( $query as $k => $v ) { $meta = get_post_custom( $v->ID ); // Get the image. $query[$k]->image = $this->get_image( $v->ID, $args['size'] ); } } else { $query = false; } return $query; } // End get_timeline_data() /** * Get the image for the given ID. * @param int $id Post ID. * @param string/array/int $size Image dimension. (default: "post-thumbnail") * @since 1.0.0 * @return string tag. */ protected function get_image ( $id, $size = 'post-thumbnail' ) { $response = ''; if ( has_post_thumbnail( $id ) ) { // If not a string or an array, and not an integer, default to 150x9999. if ( ( is_int( $size ) || ( 0 < intval( $size ) ) ) && ! is_array( $size ) ) { $size = array( intval( $size ), intval( $size ) ); } elseif ( ! is_string( $size ) && ! is_array( $size ) ) { $size = array( 150, 9999 ); } $response = get_the_post_thumbnail( intval( $id ), $size ); } return $response; } // End get_image() } // End Class ?>