Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using wordpress MU 3.3.1. I want to add a function within a loop that displays only posts with image, or featured image.

please help me on how to filter posts.

<?php get_header(); ?>
<div id="content">
<?php 
    global $post;
    $categories = get_categories('child_of=7694');  
    foreach ($categories as $category) {

        $cat_id = $category->cat_ID;

        $games = get_posts('numberposts=6&orderby=rand&category='.$cat_id);

        if ($games) : ?>

          <div class="single">

            <h1><a href="<?php echo get_category_link($cat_id); ?>"><?php echo $category->name; ?></a></h1>

           <?php foreach ($games as $post) : $do_not_duplicate = $post->ID; ?>


              <div class="game_title">

                <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php echo get_post_meta($post->ID, 'mabp_description', $single = true); ?>" >

                <?php 

                if ( (strlen($post->post_title) > 10) ) { 

                  echo substr($post->post_title, 0, 10).".."; 

                } 

                else {

                  the_title(); 

                }

                ?>

                </a>

                <br />

                <a href="<?php the_permalink() ?>" class="thumb_link" rel="bookmark" title="<?php echo get_post_meta($post->ID, 'mabp_description', $single = true); ?>"><?php 
gab_media(array(
        'name' => 'gab_featured',
        'enable_video' => 'true',
        'catch_image' => 'true',
        'enable_thumb' => 'true',
        'resize_type' => 'c', 
        'media_width' => '60', 
        'media_height' => '34', 
        'thumb_align' => 'featured_thumb', 
        'enable_default' => get_option('of_nw_enfea2'),
        'default_name' => 'featured_thumb.jpg'                                  
)); 
?>  

</a>                                   
</div>
            <?php endforeach; ?>

            <div class="cat_link"><a href="<?php echo get_category_link($cat_id); ?>">More Games</a></div>

          </div>



        <?php endif; }?>



    </div> <?php // End content div ?>



    <?php get_sidebar(); ?>

    <?php get_footer(); ?>
share|improve this question
    
You will want to look into has_post_thumbnail, WP_Query. I've written answers to do this sort of thing a dozen times before. Here's another more complex approach Cheers! –  David Apr 7 '12 at 6:04
add comment

1 Answer

global $wpdb;

$posts = $wpdb->get_results(" SELECT * FROM `wp_posts` p inner join `wp_posts` i on i.id=p.id and p.post_type='post' and i.post_type='attachment' where i.post_parent=p.id ");
share|improve this answer
    
i have put my codes in my question. please can you elaborate your answer using my codes? @Rajeev Vyas –  heradius Apr 7 '12 at 7:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.