cookies not working in wordpress
<p>I've created a meta field 'priority_priority' so that I can sort post based on how many times they have been visited..least visited post gets more priority. so whenever a visitor visits the post the priority variable is decremented.but I want priority to be decremented only on the first visit from the same user so am using cookies but the following code in not working the priority is always decremented and </p>

<pre><code> var_dump($_COOKIE['visitor'.$post_id])
</code></pre>

<p>always gives NULL</p>

<pre><code>$post_id = get_the_ID();
       $priority = get_post_meta($post_id,'priority_priority',true); 
       if($priority&gt;1)
       {     
          if(!isset($_COOKIE['visitor'.$post_id]))
          {        
               $bool=setcookie('visitor'.$post_id,$post_id,DAY_IN_SECONDS,'/');
               if(count($_COOKIE) &gt; 0)
               {
                    $priority = $priority-1;
                    update_post_meta($post_id,'priority_priority',$priority);
               }
          }

       }
 get_header();
 ?&gt;

&lt;div id="primary" class="content-area"&gt;

    &lt;main id="main" class="site-main  site-main--single" role="main"&gt;
     &lt;div&gt;
         test
     &lt;?php var_dump($_COOKIE['visitor'.$post_id]);?&gt;    
     &lt;/div&gt;
    &lt;/main&gt;&lt;!-- #main --&gt;

&lt;/div&gt;&lt;!-- #primary --&gt;
</code></pre>