![]() |
![]() |
![]() |
||||
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. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 | |
Monger Cash
Industry Role:
Join Date: Jul 2010
Posts: 2,773
|
Quote:
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 ); } The above of course assuming that you only want posts with a featured image... if not then http://codex.wordpress.org/Function_...post_thumbnail |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
(>^_^)b
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. ![]()
__________________
![]() 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.. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 | |
Confirmed User
Industry Role:
Join Date: Aug 2002
Location: USA
Posts: 6,721
|
Quote:
__________________
icq 156131086 |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 | |
Monger Cash
Industry Role:
Join Date: Jul 2010
Posts: 2,773
|
Quote:
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. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
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. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 | |
Confirmed User
Industry Role:
Join Date: Aug 2002
Location: USA
Posts: 6,721
|
Quote:
__________________
icq 156131086 |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
Monger Cash
Industry Role:
Join Date: Jul 2010
Posts: 2,773
|
Quote:
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; |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 | |
Monger Cash
Industry Role:
Join Date: Jul 2010
Posts: 2,773
|
Quote:
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. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |