[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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