mightypixel
Member
Posted 1 year 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);
}
?>
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.
mightypixel
Member
Posted 1 year 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.
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?
mightypixel
Member
Posted 1 year ago #
I am using Twentyeleven, and this is in the content.php, called in by index.php.
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.
mightypixel
Member
Posted 1 year ago #
That did the trick! Thanks a million...
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.
mightypixel
Member
Posted 1 year ago #
Thanks for the reminder; just did that.
Cheers.