Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

remove post via ajax

jQuery(function($){
	$('body.post-type-post .row-actions .trash a').click(function( event ){

		event.preventDefault();

		var url = new URL( $(this).attr('href') ),
		    nonce = url.searchParams.get('_wpnonce'), // MUST for security checks
		    row = $(this).closest('tr'),
		    postID = url.searchParams.get('post'),
		    postTitle = row.find('.row-title').text();


		row.css('background-color','#ffafaf').fadeOut(300, function(){
			row.removeAttr('style').html('<td colspan="5">Post <strong>' + postTitle + '</strong> moved to the Trash.</td>').show();
		});

		$.ajax({
			method:'POST',
			url: ajaxurl,
			data: {
				'action' : 'moveposttotrash',
				'post_id' : postID,
				'_wpnonce' : nonce
			}
		});

	});
});
Source by rudrastyh.com #
 
PREVIOUS NEXT
Tagged: #remove #post #ajax
ADD COMMENT
Topic
Name
8+1 =