[wp-hackers] Delete Row - Refreshes Page but not DB

J.D. Grimes jdg at codesymphony.co
Sat Oct 19 17:40:56 UTC 2013


Hey man, that's tough. I'm glad you've got the code working though. 

> I finally got JDs code working but I have to place this in my functions for
> ajax to work:
> 
> add_action('wp_head','custom_head');
> 
> function custom_head()
> {
> 	echo '';
> }
> 
> 
> Is that alright?  Otherwise I get ajaxurl undefined error.  

I'm not sure why this would have an effect… If you are using the code on the front end of your site, ajaxurl won't be defined - it is only defined by default in the administration panels. You would need to use wp_localize_script().

> Additionally, the json response works too! However one query always fails.  
> 
> $file = $_POST['file'];
> $del_image = wp_delete_attachment( $row['file'] ); - fail
> 
> I also tried this as an sql query:
> 
> $file = $_POST['file'];
> $fileQry = $wpdb->prepare("DELETE FROM wp_posts WHERE id = %s", $file);
> $go_fileQry = $wpdb->query($fileQry);
> 
> It still fails.  It IS possible to run multiple queries this way right?  

Is it completely failing? The wp_delete_attachment() call will only move the attachment to the trash by default -if you want to delete it permanently you need to set the second parameter to true.

-J.D.


More information about the wp-hackers mailing list