?
Solved

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

Posted on 2014-04-03
3
Medium Priority
?
201 Views
Last Modified: 2014-04-25
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
Comment
Question by:andieje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Walter Ritzel
ID: 39983074
Can you give the tables structure and the relationship between them? I can build the SQL script.
0
 

Accepted Solution

by:
andieje earned 0 total points
ID: 40011391
Apparently this function dletes the post and its atachments

https://codex.wordpress.org/Function_Reference/wp_delete_post
0
 

Author Closing Comment

by:andieje
ID: 40022161
The function i found solved the issue
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question