Thread: PHP question
View Single Post
Old 07-01-2013, 08:56 PM  
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by BCyber View Post
I'm trying to change some code to get ONLY the featured images from the media library in wordpress. I'm losing my mind, any ideas? Here's some of the code.
Code:
{
	
	$homepage_items = -1;

	$args = array( 
	    'post_type' => 'attachment', 
	    'numberposts' => $homepage_items, 
	    'post_status' => null, 
	    'post_parent' => $post->ID,
	    'order' => 'ASC',
	    'orderby' => 'menu_order',
            'meta_key' => '_thumbnail_id'
	); 
	$all_photo_arr = get_posts( $args );
}
You could also then sort them by meta_value if you so desire using "'orderby' => 'meta_value'" and then set "'order' => 'ASC|DESC'" (either or, not both)

The above of course assuming that you only want posts with a featured image... if not then http://codex.wordpress.org/Function_...post_thumbnail

Last edited by vdbucks; 07-01-2013 at 09:01 PM..
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote