So I had asked (in retrospect a pretty non-question) at https://wordpress.stackexchange.com/questions/49705/a-little-help-cleanup-from-a-real-coder/49712#49712 and one of the comments was to not use query_posts and instead use WP_Query. So I did a little digging and tried to implement that, now the code isn’t working fully. The MultiPostThumbnails isn’t pulling the img I’m only getting the the_post_thubnail not additional img. What am I doing wrong here?
function efs_get_slider(){
$slider= '<div id="ctslider">
<div class="flexslider">
<ul class="slides">';
$my_posts = new WP_Query();
$efs_query= "post_type=slider-image";
$my_posts->query($efs_query);
if($my_posts->have_posts()) : while ($my_posts->have_posts()) : $my_posts->the_post();
$flexID = $my_posts->ID;
$img1= wp_get_attachment_image( get_post_thumbnail_id($flexID),'full',0 );
$imagemain = preg_replace( '/(width|height)="d*"s/', "", $img1 );
if (class_exists('MultiPostThumbnails')) {
$image_name = 'feature-image-2';
if (MultiPostThumbnails::has_post_thumbnail('slider-image', $image_name)) {
$image_id = MultiPostThumbnails::get_post_thumbnail_id(
'slider-image',
$image_name,
$flexID
);
$attr = array('class' => "secondaryslider");
$image = wp_get_attachment_image( $image_id, 'full', false, $attr );
$imagesecondary = preg_replace(
'/(width|height)="d*"s/',
"",
$image
);
}
};
$cttitle = get_the_title();
$ctexcerpt = get_the_excerpt();
$slider.='<li><div class="fourcol secondaryimg">'.$imagesecondary.'</div>';
$slider.='<div class="threecol flex-caption"><h3>'.
$cttitle.'</h3><p>'.$ctexcerpt.'</p></div>';
$slider.='<div class="fivecol last">'.$imagemain.'</div></li>';
endwhile; endif; wp_reset_postdata();
$slider.= '</ul>
</div></div>';
return $slider;
}
I’m not familiar with MultiPostThumbnails, but I suspect your problem is:
That code appears to be trying to get the ID of the WP_Query object itself. I don’t think that exists. Even if it does, it won’t do you much good.
Rather, use this:
That code gets the ID of the current post in the loop.
In general, make sure to review the WP_Query codex page. You can tighten things up quite a bit. For instance, your whole query can be on one line: