Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 07-01-2013, 08:47 PM   #1
BSleazy
Confirmed User
 
Industry Role:
Join Date: Aug 2002
Location: USA
Posts: 6,721
PHP question

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',
	); 
	$all_photo_arr = get_posts( $args );
}
__________________
icq 156131086
BSleazy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-01-2013, 08:56 PM   #2
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
Old 07-01-2013, 08:58 PM   #3
Colmike9
(>^_^)b
 
Colmike9's Avatar
 
Industry Role:
Join Date: Dec 2011
Posts: 7,224
This should get the URL of only the featured image:

<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<stuff><img src='<?php echo $image[0]; ?>'/></stuff>

<?php endif; ?>

Edit: Might not be what you're looking for. Look at the reply above.
__________________
Join the BEST cam affiliate program on the internet!
I've referred over $1.7mil in spending this past year, you should join in.
I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years..

Last edited by Colmike9; 07-01-2013 at 08:59 PM..
Colmike9 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-01-2013, 09:19 PM   #4
BSleazy
Confirmed User
 
Industry Role:
Join Date: Aug 2002
Location: USA
Posts: 6,721
Quote:
Originally Posted by Colmike7 View Post
This should get the URL of only the featured image:

<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<stuff><img src='<?php echo $image[0]; ?>'/></stuff>

<?php endif; ?>

Edit: Might not be what you're looking for. Look at the reply above.
Ya I know how to do all that but this is different. It's part of a function and I need to get all of the featured images from the media library. Displaying them individually isn't a problem.
__________________
icq 156131086
BSleazy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-01-2013, 09:46 PM   #5
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by BCyber View Post
Ya I know how to do all that but this is different. It's part of a function and I need to get all of the featured images from the media library. Displaying them individually isn't a problem.
See my post above... noting specifically the "'meta_key' => '_thumbnail_id'" in the query args...

If, however, you want to discard all other post data except for the featured image info, then you'll have to do a more advanced query with wpdb, join some tables and such... I could give you an example if this is what you want to do, but to be honest, the savings in overhead won't be that great compared to just running a normal query like I gave you above.
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-01-2013, 09:52 PM   #6
MainstreamGuy
So Fucking Banned
 
Industry Role:
Join Date: Oct 2011
Posts: 477
I'm always surprised by the amount of people on GFY that are PHP experts.

It's like the 2013 average webmaster knows about everything, programming, marketing, design, blogging, tubes, etc etc...

They are true geniuses when you compare them with webmasters from year 2005.
MainstreamGuy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-01-2013, 09:55 PM   #7
BSleazy
Confirmed User
 
Industry Role:
Join Date: Aug 2002
Location: USA
Posts: 6,721
Quote:
Originally Posted by vdbucks View Post
See my post above... noting specifically the "'meta_key' => '_thumbnail_id'" in the query args...

If, however, you want to discard all other post data except for the featured image info, then you'll have to do a more advanced query with wpdb, join some tables and such... I could give you an example if this is what you want to do, but to be honest, the savings in overhead won't be that great compared to just running a normal query like I gave you above.
I did try your example about but all the posts/thumbs disappeared so I don't know what the problem is.
__________________
icq 156131086
BSleazy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-01-2013, 10:12 PM   #8
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by BCyber View Post
I did try your example about but all the posts/thumbs disappeared so I don't know what the problem is.
Try changing "$all_photo_arr = get_posts( $args );" to "$all_photo_arr = new WP_Query($args);"

The following works as intended for me:

Code:
$args  = array(
                      'post_type' => 'post', 
                      'meta_key' => '_thumbnail_id', 
                      'posts_per_page' => 50,
                      'paged' => $paged
                     );
$all_photo_arr = new WP_Query($args);

if ( $all_photo_arr->have_posts() ) :
  while ( $all_photo_arr->have_posts() ) : $all_photo_arr->the_post();
    the_post_thumbnail();
  endwhile;
endif;
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-01-2013, 10:14 PM   #9
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by MainstreamGuy View Post
I'm always surprised by the amount of people on GFY that are PHP experts.

It's like the 2013 average webmaster knows about everything, programming, marketing, design, blogging, tubes, etc etc...

They are true geniuses when you compare them with webmasters from year 2005.
Strange, I didn't see anyone claim to be a php expert. All I saw was someone ask a question and 2 people attempting to answer that question.

I'm always surprised at how many more trolls than non-trolls there are on gfy...

It's like the 2013 average GFY member is nothing but a waste of space, offers nothing but garbage in their posts and serves no other purpose than to disrupt the few of us who are actually trying to get shit done.

Last edited by vdbucks; 07-01-2013 at 10:26 PM..
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-01-2013, 10:36 PM   #10
BSleazy
Confirmed User
 
Industry Role:
Join Date: Aug 2002
Location: USA
Posts: 6,721
What you posted above should work but it's not. There's something else I'm missing, I didn't post all the code. I'll screw around with it tomorrow when I'm not tired. Thanks for helping though!
__________________
icq 156131086
BSleazy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.