{"id":2337919,"date":"2011-10-09T08:38:42","date_gmt":"2011-10-09T08:38:42","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/do_not_duplicate-for-a-widget\/"},"modified":"2016-08-20T02:48:37","modified_gmt":"2016-08-20T02:48:37","slug":"do_not_duplicate-for-a-widget","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/do_not_duplicate-for-a-widget\/","title":{"rendered":"do_not_duplicate for a widget"},"content":{"rendered":"<p>Hello everybody !<br \/>\ni&#8217;m trying to create my first theme, and experiencing problems with creating a widget and duplicated post&#8230;<br \/>\ni found the other posts about this subject but can&#8217;t find out what&#8217;s happenig to me&#8230; so here it is..<br \/>\ni 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&#8217;nt exist yet in the widget !<br \/>\nhere is the simple code :<br \/>\nin index.php i have :<\/p>\n<pre><code>&lt;?php \/\/Loop 1\n$loop1 = new WP_query(&#039;cat=0&amp;showposts=2&#039;);\nif($loop1-&gt;have_posts()) : while($loop1-&gt;have_posts()) : $loop1-&gt;the_post();\n$do_not_duplicate[] = $post-&gt;ID;\nthe_title(); echo &quot;&lt;br&gt;&quot;;\n endwhile; endif; ?&gt;<\/code><\/pre>\n<p>and in my widget :<\/p>\n<pre><code>&lt;?php \/\/Loop 2\n\n$loop2 = new WP_query(&#039;order=DESC&amp;showposts=100&#039;);\nwhile($loop2-&gt;have_posts()) : $loop2-&gt;the_post();\n\nif(in_array($post-&gt;ID, $do_not_duplicate)) continue;\nupdate_post_caches($posts); ?&gt;\n&lt;br \/&gt; &lt;?php  echo the_title();\nendwhile;  ?&gt;<\/code><\/pre>\n<p>and the result is here&#8230;<br \/>\nWarning: in_array() expects parameter 2 to be array, null given in <\/p>\n<p>the do_not_duplicate doesn&#8217;t exist in the widget&#8230;<\/p>\n<p>any advice about what i did wrong ?<\/p>\n<p>thanks&#8230;<\/p>\n","protected":false},"template":"","class_list":["post-2337919","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2337919","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2337919\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=2337919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}