get_posts()
can receive an argument describing which post status to operate. I would say something like this:
function remove_all_kba_data(){
//remove articles
$articles = get_posts(
[
'post_type' => 'kb_kba',
'posts_per_page' => -1,
'post_status' => [ 'published', 'draft' ]
]
);
foreach( $articles as $article ) {
//delete post, bypass trash
wp_delete_post( $article->ID, true);
}
}
Related Posts:
- Add custom Attachment Display Setting for images
- Rewriting post slug before post save
- Getting the post_id in wp_ajax function
- Replacing all attachment links in post with media file link
- Change the default number of posts to show on mobile version
- I am trying to create a simple frontend form for posting
- Post content being duplicated by the_content();
- How can I pass $post object to ‘save_post’ add_action?
- 1 column admin screen options – move submitdiv to bottom
- Single Post Navigation Within Each Category
- Add confirmation popup on “Move to Trash”
- How to get the latest posting time of archived pages in WordPress?
- Insert posts in two tables
- get_next_post() not working
- How To Keep Posts from Being Displayed Two or More Times on My Homepage? [closed]
- custom wordpress post loop – hide iframe content
- Different template for posts of all subcategories of category
- Search for posts based on their url in the admin?
- Add custom field automatically (add_post_meta) with value based on number of words of article
- How to access featured image?
- Mark menu item as current-menu-item for category
- Replace ‘published on date’ with ‘modified on date’ on Posts
- How to display category from recent posts?
- Best way to assign post position in a news site homepage? (no categories, no sticky posts)
- How do I restart my loop with get_next_post()?
- How do I use WP_Query to get a range of posts with custom fields that have numbers with letters in them?
- “Duplicate” Posts Appearing Since 3.1.2 Update
- Rename “post” to “article” throughout the admin back end [duplicate]
- Setup a custom dynamic post
- How to make a price range slider from get_post_meta?
- One menu for frontpage (one pager), and a different menu for posts
- pagination for single post by category
- Adding an image to a non existing post
- How to create new post content templates for my users?
- Start post pagination at 0 instead of 1
- Is it possible to add/tick a category to a post when it is created?
- How many posts does the loop return?
- Posts loop displaying the same post data
- Display Posts on Custom Page
- Blog Post On Home Page Displaying Page Published Date Not Post Published Date
- Counter is skipping post when I still want it visible [closed]
- The_excerpt() doesn’t parse – how to change that?
- Can’t understand why sometimes a [caption] field appears
- Trying to edit archive.php to only show post extract, with featured image
- Divs appearing everywhere in post content
- Latest posts by category — how to exclude current post?
- Extracting relevant tags associated with that particular single post only
- Why in my query is display two title?
- Posts page not showing correct image
- wp_query with ajax
- Custom posts listing widget always returns 1 extra result
- Post Title List on home page with time
- Add “Posted on” to post date
- Use posts_where to exclude posts ids from wp_query
- Get x recent posts by author?
- How to compare post tags?
- Get a term each custom post type
- Delete all Tag Links from Posts
- Adjust the order for returned posts
- Post in bulk based on category template
- Delete Post but retain image of post [WP REST API]
- user_has_cap filter allows “edit_others_posts” but not is not allowing updating/publishing
- how to add tags to post in the Loop?
- Yoast breadcrumb URL shows category instead of the page
- Add data attribute of post_id for Internal links
- Menu Items disappearing/being empty on save or post edit
- Display/Filter post using if else statement
- Search results for ACF data
- Why does my “Add New Post” page have an old post in it?
- link to edit a post has empty target
- Nestling Posts Under Page & Justify Text
- Redirect to custom post if custom archive page has just one result?
- Adding posts updates previous post
- Strange behaviour in WordPress admin
- How do you update post date (year only) in a separate custom field?
- Creating a link to the first post in a category
- sometimes on saving a post as draft, it says Access Denied You don’t have permission to access “mywebsite.com/wp-admin/post.php”
- How do I change the post title’s link on the posts page?
- WordPress text field in array problem
- List Authors For Current Category
- Get query result according to merged array
- cleaning out posts that don’t exist anymore but links are still there
- Custom URL Structure for posts with subcategories
- Possible to display X number of authors posts from another WordPress site?
- Theme Unit testing not importing on MAMP server – Fatal error: Maximum execution time of 60 seconds exceeded
- Post/Edit/Delete Post From Frontend… How?
- Add tags to post before it’s created
- can’t post immediately
- Use radio buttons & checkboxes for post categories
- List posts that are in the same category as the current post title
- Wanting to apply different featured images for each post
- Password-protected Posts lead to 404 Error
- Multiple blog “feeds” in a single blog each with distinctly styled post pages
- How to get pagination working with “Pending” Posts
- How do I show the post title if an advanced custom field hasn’t been used?
- Post’s arent displaying
- Show with echo if a post has two or more categories
- Can I get custom post items in select box (dropdown)
- How to automatically convert a form with HTML link into post
- WordPress Post Updating is Not Working