• Hello, is it possible from the code I gave below to add a button to delete the post?
    That is, the user can delete his posts

    <?php
     $current_user = wp_get_current_user();
    $args = array(
    'author'        =>  $current_user->ID,
    'orderby'       =>  'post_date',
    'order'         =>  'post_date',
    'post_status' => 'publish',
    'category'         => '1',
    'posts_per_page' => -1
    );
    
    $current_user_posts = get_posts( $args );
    //echo "<pre>"; print_r($current_user_posts); die; 
    foreach ($current_user_posts as $post) {
    
    ?>
     <div class="containera">
     <div class="text-blocka2">
        <p><?php $category_detail=get_the_category($post->ID);//$post->ID
                    foreach($category_detail as $cd){ ?>
    <?php echo $cd->cat_name; ?>
    <?php } ?></p>
      </div>
     
    <?php
    $image = get_field( 'field_5e1f6f6862891', $post_object->ID ); if( !empty($image) ): ?>
     <img alt="" style="width:600px; height:300px;"  src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
     <?php endif; ?>
      <div class="text-blocka">
        <h4><a href="<?php echo $post->guid; ?>" rel="bookmark"><?php echo $post->post_title; ?></a></h4>
        <p><?php the_field('field_5e1f6eb36288d'); ?></p>
      </div>
    </div> 
    <br>
    <?php } ?>
    • This topic was modified 5 years, 1 month ago by joorkataa.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes it is possible. The easiest would be to simply add a “Delete” link that is similar to the “Trash” link seen on the posts list table in the admin area. Use get_delete_post_link() to create the proper link URL. You can style the link as a button if you like.

    Deleting via Ajax so the user does not need to leave the page would be a better UX, but developing it would be much more involved.

Viewing 1 replies (of 1 total)
  • The topic ‘Delete button on frontend’ is closed to new replies.