• Hello

    I have the following code in a slider template of mine called slider.php:

    <?php
    
                $myCategories[] = get_term_by('name', 'Featured', 'category');
    
                $args = array(
                'numberposts'     => 5,
                'offset'          => 0,
                'category'        => $myCategories[0]->term_id,
                'orderby'         => 'post_date',
                'order'           => 'DESC',
                'post_type'       => 'post',
                'post_status'     => 'publish',
                'suppress_filters' => true );
    
                $myposts = get_posts( $args );
    
                foreach( $myposts as $post ) :	setup_postdata($post); ?>
    
                    <div data-thumb="<?php $feat_image_small = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'feature-small') ); echo $feat_image_small; ?>">
                        <img src="<?php $feat_image_big = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'feature-big') ); echo $feat_image_big; ?>">
                        <div class="caption elemHover fromRight" style="bottom:65px; padding-bottom:5px; color:#ff0; text-transform:uppercase">
                            <a href="<?php the_permalink(); ?>" style="color:#ff0;"><?php the_title(); ?></a>
                        </div>
                        <div class="caption elemHover fromLeft" style="padding-top:5px;">
                            <?php $little_excerpt = substr(get_the_excerpt(),0,100); $read_more ='<a href="'.get_post_permalink().'" style="color:#ff0;">Read More...</a>'; echo $little_excerpt; echo $read_more; ?>
                        </div>
                    </div>
    
                <?php endforeach; ?> <?php
            ?>

    This code works perfectly as I intended for it to work.

    I call this template file in the header file with get_template_part.

    Now my issue is this, I want to limit my index.php(home) to only display posts that has not already been called by the slider like “Featured” posts.

    Lets say for arguments sake that I have a “Featured” category and that there are 10 posts in that category.

    The slider will grab 5 of these posts and display them but the main loop in index.php will also include these 5 posts.

    Don’t get me wrong I don’t want to exclude the entire “Featured” Category only the ones that were dynamically displayed in the slider.

    Any help in this regard will me much appreciated!

    Thanks a mil!

  • The topic ‘get_posts exclude some posts’ is closed to new replies.