WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Duplicate Posts from Category Query on Home Page (9 posts)

  1. blurb
    Member
    Posted 2 years ago #

    Hello everyone,

    The following code returns duplicate posts no matter what I try.

    Your help is much appreciated.

    <?php
    	if ( is_home() ){
    		$args=array(
    			'posts_per_page' => 3,
    			'post__not_in' => $do_not_duplicate,
    			'paged' => $paged
    		);
    
    		if ( ( isset( $_GET['homeq'] ) && $_GET['homeq'] == 'today' ) || !isset( $_GET['homeq'] ) ) {
    			$args['category__in'] = array(7,8,9,10);
    		}
    
    		if ( isset( $_GET['homeq'] ) && $_GET['homeq'] == 'world' ) {
    			$args['cat'] = 8;
    		}
    
    		if ( isset( $_GET['homeq'] ) && $_GET['homeq'] == 'turkey' ) {
    			$args['cat'] = 7;
    		}
    
    		if ( isset( $_GET['homeq'] ) && $_GET['homeq'] == 'sports' ) {
    			$args['cat'] = 10;
    		}
    
    		if ( isset( $_GET['homeq'] ) && $_GET['homeq'] == 'mag' ) {
    			$args['cat'] = 9;
    		}
    
    		$args = apply_filters( 'et_home_query', $args, isset( $_GET['homeq'] ) ? $_GET['homeq'] : '' );
    
    		query_posts($args);
    	}
    ?>
  2. vtxyzzy
    Member
    Posted 2 years ago #

    Where is the variable $do_not_duplicate set? if it is not an array of post IDs, then it will not work to suppress duplicates.

  3. blurb
    Member
    Posted 2 years ago #

    Thank you for your response.

    This is a piece of code I have modified to return posts from different categories on home page, very much like the Recent, Random, Unanswered sub menu seen on (this theme). But I want posts from the selected category to return, instead of random or popular posts.

    I managed to switch this code into what I want (sort of), but now I get duplicates on each category (and sometimes posts not belonging to the selected category).

    I'm afraid I'm not very well versed in WordPress; any help in the right direction would be much appreciated.

    Cheers.

  4. vtxyzzy
    Member
    Posted 2 years ago #

    I do not see anything obvious that would cause dups. Are the duplicates possibly 'sticky' posts? Is there another query_posts call in the template?

  5. blurb
    Member
    Posted 2 years ago #

    I am using Twentyeleven, and this is in the content.php, called in by index.php.

  6. vtxyzzy
    Member
    Posted 2 years ago #

    There's your problem. There is a Loop in index.php and your query is called from inside the loop.

    Try putting your code in index.php just after the comment '/* Start the Loop */' so it will override the original query.

  7. blurb
    Member
    Posted 2 years ago #

    That did the trick! Thanks a million...

  8. vtxyzzy
    Member
    Posted 2 years ago #

    If your problem has been solved, please use the dropdown on the right to mark this topic 'Resolved' so that anyone else with this question can see that there is a solution.

  9. blurb
    Member
    Posted 2 years ago #

    Thanks for the reminder; just did that.

    Cheers.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.