• Hello everybody !
    i’m trying to create my first theme, and experiencing problems with creating a widget and duplicated post…
    i found the other posts about this subject but can’t find out what’s happenig to me… so here it is..
    i have one slider taking the 3 last posts and would like to have a widget with the other posts but it looks like my $do_not_duplicate array does’nt exist yet in the widget !
    here is the simple code :
    in index.php i have :

    <?php //Loop 1
    $loop1 = new WP_query('cat=0&showposts=2');
    if($loop1->have_posts()) : while($loop1->have_posts()) : $loop1->the_post();
    $do_not_duplicate[] = $post->ID;
    the_title(); echo "<br>";
     endwhile; endif; ?>

    and in my widget :

    <?php //Loop 2
    
    $loop2 = new WP_query('order=DESC&showposts=100');
    while($loop2->have_posts()) : $loop2->the_post();
    
    if(in_array($post->ID, $do_not_duplicate)) continue;
    update_post_caches($posts); ?>
    <br /> <?php  echo the_title();
    endwhile;  ?>

    and the result is here…
    Warning: in_array() expects parameter 2 to be array, null given in

    the do_not_duplicate doesn’t exist in the widget…

    any advice about what i did wrong ?

    thanks…

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Daniel B

    (@lebus)

    i forgot to say, of course if i put the 2 loops in the same file it works..
    it’s really something i thing about the widget, maybe it’s initialising before the index.php ?

    thanks for any help..

    try to declare $do_not_duplicate as a global variable;

    at the beginning of both codes, add for example:

    global $do_not_duplicate;

    Thread Starter Daniel B

    (@lebus)

    thanks for the answer.. but it’s still not working, it looks like the widget are being loaded before and so does not see the do_not_duplicate variable… strange ??
    anyone ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘do_not_duplicate for a widget’ is closed to new replies.