0

I've built a membership site where users can post listings from the frontend, edit those, and ideally also delete them.

For the latter, I'd like to echo a "delete post" link to the frontend. The problem is that get_delete_post_link().

So from this: $theID = get_the_ID(); // inside loop echo $theID; <a href="<?php echo get_delete_post_link( $theID, '', false ); ?> ">Delete This Post</a>

I get: 123 /* = $theID; */ <a href="_">Delete This Post</a>

I tried the following things:

  • passing only $theID as argument instead of the full three
  • passing $theID, '', true
  • ran checks as described in the answers here: Can't echo get_delete_post_link
  • the problem occurs both when I'm logged in as admin and as normal user (with added capacities)
  • I made sure the permissions for the custom post type are mapped correctly
  • outside the loop it works, but not inside the loop (the codex says it can be done within the loop: https://codex.wordpress.org/Function_Reference/get_delete_post_link).

Here's the loop I'm using:

  // arguments
  $arguments = array(
    'post_type'         => 'CustomType',
    'posts_per_page'  => -1,
    'author_name'     => $current_user->user_login
  );


  // query
  $the_query = new WP_Query($arguments);

  <?php wp_reset_query();    // Restore global post data stomped by the_post(). ?>
    <?php if( $the_query->have_posts() ): ?>
        <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
          <?php if( has_term( 'custom_term', 'custom_taxonomy' ) ): ?>
               /* stuff happens here */
               /* get_delete_post_link() returns nothing */
          <?php endif; ?>
        <?php endwhile; ?>
      <?php endif; ?>
   <?php wp_reset_query();   // Restore global post data stomped by the_post(). ?>

I'm at the end of my wits with this, any help would be appreciated.

1
  1. get_delete_post_link() Should work without parameters if you are using it inside the loop

  2. I believe that you need to remove your wp_reset_query() that is placed before the if( $the_query->have_posts()..

  • I tried both suggestions, but they sadly didn't work. get_delete_post_link() does work without arguments, but only if I place it outside of the loop, i.e. right before <?php if( $the_query->have_posts() ): ?>. – dtx Mar 21 '17 at 12:10
0

Have you turned on WP_DEBUG and checked your error log? If there is something not set up quite right with the CPT, you'll see something like:

"Notice: map_meta_cap was called incorrectly. The post type CustomType is not registered, so it may not be reliable to check the capability "delete_post" against a post of that type. Please see Debugging in WordPress for more information. (This message was added in version 4.4.0.) in /yourpath/wp-includes/functions.php on line XX"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.