Solved

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

Posted on 2014-04-03
3
197 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

696 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