First of all we need to find the posts related to our taxonomy term. Then we will delete them one by one by running a foreach
loop. Try below code. I hope that will work for you-
add_action('pre_delete_term', 'the_dramatist_delete_posts_on_taxonomy_delete', 1, 1 );
function the_dramatist_delete_posts_on_taxonomy_delete( $term ) {
$args = array(
'post_type' => 'post', // post_type
'tax_query' => array(
array(
'taxonomy' => 'post_tag', // taxonomy_name
'field' => 'id',
'terms' => $term
)
)
);
$posts = get_posts($args);
foreach ( $posts as $post ){
wp_delete_post( $post->ID, true );
}
}
Related Posts:
- cURL 28 error after switch from to brew php 7.2 on localhost
- How to loop through JSON data in wordpress WP REST API
- Creating a post with the REST API, curl and oauth returning 401 error
- Does the REST API (official) support custom post types?
- How to make an meta_query optional?
- Create a new user using WP REST API and declare meta object
- Ajax call to my WordPress website from an external application [duplicate]
- Problem with Woocommerce REST API Authentication
- How Do I Add User Custom Field to REST API Response?
- wordpress custom endpoint multiple params
- register_rest_route regex option for base64 or alternate
- Continue execution after WP REST API response
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- How to generate HMAC-SHA1 signature to use with WP REST API and OAuth1
- How do I fetch all comments per post via WP REST API?
- How to filter posts by post format “standard” from wp-json api?
- Why is the post meta[] empty when I make a call to the wordpress rest api?
- WordPress 5 WP REST routes – No errors
- Is there an equivalent to WP_Error object I can return in the case of a successful REST request?
- Woocommerce hook run after an Order been created through REST API
- what is the best practice to add new field to an api route
- How to show single category archive
- Woocommerce api: create product with images – bad request
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Are nonces in WP REST API optional by default?
- how to save selected option in variable for rest api category filter
- JSON REST API WordPress only showing first 10 categories
- Buddypress update user avatar image via REST
- Building a REST API for your web app exposes primary keys of DB records?
- How to set a template with wp_insert_post
- Permission callback to check if user has application password
- Multiple requests external data api dynamic block gutenberg
- How can I spin up a new website for a registered user automatically?
- Simple WordPress endpoint route doesn’t work
- Is it possible to create new user from external form using REST API?
- Cant register rest routs from class instance
- WordPress REST API register_rest_route give a 500 error
- WC_Customer delete function returns error
- Custom route and query
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Filter by field with array value in ACF on WP REST API
- REST API works in browser and via AJAX but fails via cURL
- How to clone all WordPress Rest API end points
- no_rest_route error on custom routes
- Flatten Responses returned via WP REST API via WP_Error for obfuscation
- WP_REST_Response – How to return Gzip answer and add Content-encoding header?
- WordPress api post image raw data without being blank in media library
- REST api returns 404 on some WordPress sites
- Integrate admin plugin into template. Very interesant (live search + autocomplete with wp rest api, in vanilla js)
- Require()/Include() post template adding extra content
- WordPress 5.6 Application Passwords
- Force REST API Authentication for each request method
- How do i post data to url with fields?
- Call WP Rest-Api to GET /users/me returned NOTHING in console
- REST API custom endpoint to fetch pages and posts not working
- WooCommerce REST API AJAX Auth – 401 response
- Looping through and combining calls to Woocommerce REST API
- get Woocommerce product format json for WP_Query
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- Require advice handling a URL redirect from a Third Party. URL Params need to populate and then forward to payment
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- Headers already sent error with get_template_part in REST API call
- Properly process a custom WP REST API request (Authenticate, Authorize + Validate)?
- How to pass and validate nonce in custom REST routes
- rest_cannot_create_user – Sorry, you are not allowed to create new users. CURL WORDPRESS REST API
- Query posts by custom taxonomy slug in WP REST API?
- oneOf JSON Schema validation not properly working for custom post meta value?
- REST API custom endpoints for metaboxes
- Authenticate + Authorize WP REST API request before built-in WP JSON Schema Payload Validation?
- Adding Microsoft Teams Incoming Webhook to WordPress, Problem with Rest Route?
- WordPress REST API – Custom field not added to pages
- How to paginate a list of custom taxonomy terms?
- reason of splitting theme files to multiple files
- How to get custom image size for image uploaded in Customizer
- How to Fetch values from WP database based on selected option value by onchange using PHP?
- WordPress child theme fails to override parent navigation menu in /inc/structure/header.php
- Customizer: Output default value in Customizer CSS
- Trying do build a contact form
- $_SESSION variables work perfectly on my local machine but returns NULL on development webserver
- Add categorys to custom post type not working
- Limit the number of child pages
- How to show upcoming events according to start date field
- Some problems in custom widget
- Call a function in functions.php from within tags (JS)
- Displaying images outside the content
- Show related products by attribute based and certain conditions
- How to retrieve taxonomy Metabox fields in frontend
- How to count active users on a specific page
- WooCommerce display price before add to cart [closed]
- Create dashboard widget for custom theme support
- How to override html codes in wordpress?
- Plugin Modification Change Functionality For Logged User Only
- Modify category archive page loop on functions.php
- How to display html code on homepage
- two wordpress sites, two themes, one database, same content
- Check if values exists DB
- Trying to exclude posts from a category on the home page
- Php conditional help needed
- Issues trying to add a href statment with PHP into a PHP Echo Statement [closed]
- Help with if/else loop [closed]