0

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(); ?>
1

1 Answer 1

1
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 ");
1
  • i have put my codes in my question. please can you elaborate your answer using my codes? @Rajeev Vyas
    – heradius
    Apr 7, 2012 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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