Forums

[resolved] Front End Delete Post with Custom Post Type (10 posts)

  1. Clicknathan
    Member
    Posted 5 months ago #

    I'm trying to implement a front end delete link such as the one found here (and similar code on other forum posts): http://wordpress.org/support/topic/delete-post-link?replies=11

    However, though that works for pages & posts, it returns a WordPress Failure screen for custom post types.

    Would anyone know how to make this work for custom post types? Perhaps it's something I need to do when registering the custom post type?

    Here's my code for registering the post type:

    add_action('init', 'wishlist_register');
    
    function wishlist_register() {
    
    	$labels = array(
    		'name' => _x('Wishlist Items', 'post type general name'),
    		'singular_name' => _x('Wishlist Item', 'post type singular name'),
    		'add_new' => _x('Add New', 'wishlist item'),
    		'add_new_item' => __('Add New Wishlist Item'),
    		'edit_item' => __('Edit Wishlist Item'),
    		'new_item' => __('New Wishlist Item'),
    		'view_item' => __('View Wishlist Item'),
    		'search_items' => __('Search Wishlist'),
    		'not_found' =>  __('Nothing found'),
    		'not_found_in_trash' => __('Nothing found in Trash'),
    		'parent_item_colon' => ''
    	);
    
    	$args = array(
    		'labels' => $labels,
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'menu_position' => null,
    		'has_archive' => true,
    		'supports' => array('title','editor','thumbnail', 'author')
    	  ); 
    
    	register_post_type( 'wishlist' , $args );
    }
  2. deepbevel
    Member
    Posted 5 months ago #

    You might try a plugin which registers custom posts, as an alternative to the code, just to see.

    This looks interesting, I too made a wish list system, I used custom posts, and my delete link worked. But I used a plugin to register the custom posts.

    wish-list-demo-site
    I even explain how I made it on the site. My delete link code should be there as well.

  3. Clicknathan
    Member
    Posted 5 months ago #

    Thanks DeepBevel, but it looks like you're using some type of "custom post template", not custom post types.

  4. deepbevel
    Member
    Posted 5 months ago #

    ooops, didn't know there was a difference. Hope you find something that works.

  5. Clicknathan
    Member
    Posted 4 months ago #

    Figured this out if anyone's interested. Turns out WP has a built in function for this. Here's my complete solution:

    What I'm doing with the code below is displaying the Delete link on the front end only if the user viewing the post is logged in as the post's author.

    <?php if ($post->post_author == $current_user->ID) { ?><p><a onclick="return confirm('Are you SURE you want to delete this Wish?')" href="<?php echo get_delete_post_link( $post->ID ) ?>">Delete post</a></p><?php } ?>

    More details on how that works here: http://goo.gl/iSP8l

  6. deepbevel
    Member
    Posted 4 months ago #

    yep, I have the same, never knew there was an issue with deleting custom posts types because I never used them.

    How are you compliing your lists? what's your system?
    I use a button-click function that allows shopping cart items to be copied as a posts to a private category/archive. the lists are organized by tag, and I have a tag search as the only means of accessing lists.

  7. Clicknathan
    Member
    Posted 4 months ago #

    This is a different kind of wishlist, Deepbevel. It allows non-profit organizations to post items they want (ie, their "wishes") to the site, and other users to contact them if they have the item. I needed them to be able to be deleted by the non-profits after they'd received the item, without logging into the backend.

  8. deepbevel
    Member
    Posted 4 months ago #

    great, and did it turn out the custom post had nothing to do with the delete code? I'm concerned as I may want to use custom post types at some point, but fortunately your code looks like mine.

  9. Clicknathan
    Member
    Posted 4 months ago #

    Well, using the code linked to in my original post, yes, it did have something to do with custom post types it appears, related to how the wp_nonce_url was being called.

    Using my latest code though, it works with custom post types.

  10. Louis_Dea
    Member
    Posted 1 month ago #

    Awesome Clicknathan. Thank you for posting the solution!

Reply

You must log in to post.

About this Topic

Tags

No tags yet.