• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

how to manually delete the attachment post and its metadata for a post

Hello

Please could you advise how I programmatically delete the wp_post row which is the featured_image of a post (e.g. type attachment) and the wp_postmeta for the attachment

All I have is the post_id

Is there a way to do this using built in wordpress functions or could you advise of the sql I would need to run if I was calling $wpdb->query to do it.

I'm getting a bit confused as its late here :) and I know i need to get the _attachment_id postmeta for the original post and then delete the post with that id and its wp-meta.

I can come up with convoluted ways to do this but I imagine there is a quicker or efficient way to do it already built in

Thanks
0
andieje
Asked:
andieje
  • 2
1 Solution
 
Walter RitzelSenior Software EngineerCommented:
Can you give the tables structure and the relationship between them? I can build the SQL script.
0
 
andiejeAuthor Commented:
Apparently this function dletes the post and its atachments

https://codex.wordpress.org/Function_Reference/wp_delete_post
0
 
andiejeAuthor Commented:
The function i found solved the issue
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now