Solved

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

Posted on 2014-04-03
3
186 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
  • 2
3 Comments
 
LVL 15

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In Part I (http://www.experts-exchange.com/Web_Development/Blogs/WordPress/A_8410-Getting-Started-In-WordPress-Part-I.html), I introduced you to the powerful WordPress backend, the WordPress administrative Dashboard.  In Part II, I will introduce yo…
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!
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now