WordPress.org

Ready to get started?Download WordPress

Forums

Exclusion of posts (2 posts)

  1. mageguild
    Member
    Posted 1 year ago #

    On my homepage, I have 2 modules. "Featured Content" and "Most Recent Content." What I would like to do is exclude posts from showing Most Recent if they are showing in the Featured Content module.

    When I have one featured item, the exclusion is working fine. When there are multiple featured items, only the first item is being excluded.

    Below is my code. Any assistance would be great.

    Cheers,

    //Get Featured Posts

    $featureCheck = query_posts("showposts=".get_option('studioblue_featured_num')."&meta_key=is_post_featured&meta_value=1");
    $postids = array();
    foreach ($featureCheck as $catpost) {
    $postids[]=$catpost->ID;
    }
    $mypostids = implode (', ', $postids);

    //Get Most Recent and exclude featured

    $args=array(
    'post_type' => array('post','video', 'gallery', 'poll', 'discussions'),
    'post_status' => 'publish',
    'paged' => $paged,
    'posts_per_page' => 10,
    'category__not_in' => array(51,77,76),
    'post__not_in' => array($mypostids)

    );

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    http://codex.wordpress.org/Forum_Welcome#Posting_Code

    because $mypostids is already an array, your 'implode' code does make no sense.
    also, I am not sure if a 'foreach' loop would work with the 'query_posts()' code; try to use 'get_posts()' instead;

    //Get Featured Posts
    
    $featureCheck = get_posts("showposts=".get_option('studioblue_featured_num')."&meta_key=is_post_featured&meta_value=1");
    $postids = array();
    foreach ($featureCheck as $catpost) {
    $postids[]=$catpost->ID;
    }
    
    //Get Most Recent and exclude featured
    
    $args=array(
    'post_type' => array('post','video', 'gallery', 'poll', 'discussions'),
    'post_status' => 'publish',
    'paged' => $paged,
    'posts_per_page' => 10,
    'category__not_in' => array(51,77,76),
    'post__not_in' => $mypostids 
    
    );

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.