title: Wordpress wp_nonce_url inside a while loop (multiple posts grid)
body: <p>In wordpress we have a grid with posts from a custom CPT called Routes.</p>
  <pre><code>&lt;div class=&quot;activities-sections&quot;&gt;
   &lt;?php 
   $user_id = get_current_user_id();
   $post_count = 1;
      $args = array(
          'post_type' =&gt; 'routes',
          'posts_per_page' =&gt; -1,
          'post_status' =&gt; 'publish',
          'author' =&gt; $user_id,
      );
       $query = new WP_Query($args);
      if ( is_user_logged_in() ) {
      if ($query-&gt;have_posts()) :?&gt;
          &lt;div class=&quot;activities-container&quot;&gt;
              &lt;div class=&quot;activities-wrap&quot;&gt;
                  &lt;?php 
                while ($query-&gt;have_posts()) : $query-&gt;the_post();
                  ?&gt;
                  &lt;div class=&quot;activities-box-list&quot;&gt;
                    &lt;div class=&quot;activities-box&quot;&gt;
                        &lt;div class=&quot;activities-img&quot;&gt;
          &lt;a href=&quot;&lt;?php echo the_permalink()?&gt;&quot;&gt;                        &lt;?php the_post_thumbnail('full');?&gt; &lt;/a&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;activities-content&quot;&gt;
                              &lt;div class=&quot;card-heading-destinations&quot;&gt;
                                &lt;p&gt;&lt;?php the_title(); ?&gt;&lt;/p&gt;
                                &lt;span class=&quot;icon-heading&quot; style=&quot;border-bottom:2px solid &lt;?php the_field('choose_border_color'); ?&gt;&quot;&gt;
                                    &lt;?php $icon_heading = get_field('heading_icon');
                                      if($icon_heading): echo '&lt;img src=&quot;'.$icon_heading.'&quot;&gt;'; ?&gt;
                                    &lt;?php endif; ?&gt;
                                &lt;/span&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;content-paragraph&quot;&gt;
                                &lt;?php $excerpt = get_the_excerpt(); echo substr($excerpt, 0, 300).&quot;&quot; ;?&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;button-dest-post&quot;&gt;&lt;a href=&quot;&lt;?php echo the_permalink()?&gt;&quot;&gt;ΔΕΙΤΕ ΑΝΑΛΥΤΙΚΑ 
                              &lt;span class=&quot;button-icon&quot;&gt;
                                  &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;37&quot; height=&quot;33.002&quot; viewBox=&quot;0 0 37 33.002&quot;&gt;
                                  &lt;defs&gt;
                                  &lt;filter id=&quot;eye_icon&quot; x=&quot;0&quot; y=&quot;0&quot; width=&quot;37&quot; height=&quot;33.002&quot; filterUnits=&quot;userSpaceOnUse&quot;&gt;
                                  &lt;feOffset dy=&quot;4&quot; input=&quot;SourceAlpha&quot;/&gt;
                                  &lt;feGaussianBlur stdDeviation=&quot;3.5&quot; result=&quot;blur&quot;/&gt;
                                  &lt;feFlood flood-opacity=&quot;0.078&quot;/&gt;
                                  &lt;feComposite operator=&quot;in&quot; in2=&quot;blur&quot;/&gt;
                                  &lt;feComposite in=&quot;SourceGraphic&quot;/&gt;
                                  &lt;/filter&gt;
                                  &lt;/defs&gt;
                                  &lt;g transform=&quot;matrix(1, 0, 0, 1, 0, 0)&quot; filter=&quot;url(#eye_icon)&quot;&gt;
                                  &lt;path id=&quot;eye_icon-2&quot; data-name=&quot;eye icon&quot; d=&quot;M430,3901s-3.582,6-8,6-8-6-8-6h0s3.582-6,8-6,8,6,8,6h0Zm-8-5c-2.848,0-5.621,3.235-6.81,4.995.932,1.364,3.712,5.006,6.81,5.006,2.848,0,5.621-3.234,6.81-5C427.878,3899.64,425.1,3896,422,3896Zm0,9a4,4,0,1,1,4-4A4,4,0,0,1,422,3905Zm0-7a3,3,0,1,0,3,3A3,3,0,0,0,422,3898Z&quot; transform=&quot;translate(-403.5 -3888.5)&quot; fill=&quot;#3c4042&quot;/&gt;
                                  &lt;/g&gt;
                                  &lt;/svg&gt;
                              &lt;/span&gt;
                              &lt;/a&gt;
                              
                            &lt;/div&gt;
                        &lt;/div&gt;
                        &lt;?php
   //$url = get_bloginfo('url');
                                      $post_id = get_the_ID();
    if (current_user_can('edit_post', $post-&gt;ID)){
  echo '&lt;a class=&quot;delete-post&quot; href=&quot;';
  echo wp_nonce_url(&quot;$url/wp-admin/post.php?action=trash&amp;post=$post_id&quot;, 'delete-post_' .                $post-&gt;ID);
  echo '&quot;&gt;Delete post&lt;/a&gt;';
   }
   ?&gt;
                    &lt;/div&gt;  
                  
  
                  &lt;/div&gt;
                  &lt;?php 
                  endwhile; 
                  ?&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;?php endif;  wp_reset_postdata(); ?&gt;
  </code></pre>
  
  
  <p>Under each post i want to add a link &quot;Delete post&quot; post so logged in users will be able to delete specific post when clicking on it.</p>
  <p>I have used function wp_nonce_url.</p>
  <p>The problem is that _wpnonce= generated the same value for all posts in the grid.</p>
  <p>For example if i have 10 posts in the loop _wpnonce= will always will be _wpnonce=10a2e64a4b for all 10 posts.</p>
  <p>Any idea how to make work correctly in a loop? Any code?</p>
  <p>I believe each post must have a unique _wpnonce= so when we click on delete post it will delete the specific post.</p>
  <p>Right now when i click delete post on any grid item i get:
  &quot;The link you followed has expired.&quot;.</p>
  <p>Any ideas?</p>