I believe I found the problem. Since the wp_delete_post was before the redirect, WordPress tried to reload an inexistent page (and comments, since they are deleted automaticaly with the command) and that generated the error.
The new code is as such and it’s not generating errors:
if( has_post_thumbnail( $post_id ) ) {
$imagem_principal_id = get_post_thumbnail_id( $post_id );
wp_delete_attachment( $imagem_principal_id , true );
}
if( get_post_meta( $post_id , 'token_personagem' , true ) ) {
$token_id = get_post_meta( $post_id , 'token_personagem' , true );
wp_delete_attachment( $token_id , true );
}
wp_redirect( $url );
wp_delete_post( $post_id );
exit;
Also, you may notice I added exit
to the code. That is to follow guidelines in here.
Related Posts:
- Submit post and upload image from front-end
- How to set a custom post type to not show up on the front end
- Front end post editing using a form
- Add custom post type items from frontend
- Front end registration/login & publish/update 1 custom post
- List custom post types in dropdown
- How I upload, save and set a featured image from my frontend?
- Trying to save custom post type from frontend partially working
- Reason action hook won’t work with update_post_meta from frontend form? Alternative?
- front end radio custom taxonomy with custom post type
- Assign category to front end post
- Front end post form won’t post categories to custom post type
- Create and edit posts from front end
- Make custom post type display as a page
- Before Delete Post
- Frontend Form for Custom Post Type
- Upload Image from Front End and Resize
- Frontend posting – everything saves other than checkboxes?
- I am having a problem with form updating/editing WordPress post on the frontend
- WordPress Create Post from front-end
- wp_set_object_terms() not adding new term to custom post and custom taxonomy
- How to restrict CPT post’s fronted view only for specific user roles?
- How to save custom taxonomy from front end post submission
- Insert Custom Post Type data from the front-end by a user
- Crafting WP_Query array, sort by date
- Posting to a Custom Post Type from front end – user generated content
- How to get the upcoming post ID from front end?
- How to make front end form only accept certain values
- Custom Post Type & Meta Box – Displaying meta box information on front end?
- How To Import CPT With Only Few TEXT ACF Fields From Front End?
- Submitting Custom Post Types with custom fields from Front-end form
- After creating Custom post type by user delete old one
- Get id from metabox dropdown
- Get admin area editor in frontend
- Better approach for a WordPress Inventory
- Display custom meta on page that has been check in custom post type
- Update ACF fields on a frontend form? [closed]
- Add term for custom taxonomy from front end
- Post visibility option to theme front-end for author to select?
- display custom portfolio tags
- Plugin needed to allow subscribers to post articles on the front end without admin approval [closed]
- How to create Custom image post?
- Front-end Image Upload to Custom Meta Box
- Auto delete pages/posts without views
- Preview url not working outside wp-admin
- Change custom post taxonomy values from front-end
- Saving Child Terms on front end not setting parent
- WordPress Front-End user restricted taxonomies
- Multi Photo Upload with Caption on Front End for Custom Post Type
- Front End users account with lots of user Roles (not Woocommerce)
- Show “Republished” badge when Post Date is manipulated
- Getting Custom post category from Form
- Add a meta to custom post type which corresponds to a particular taxonomy
- Add a image to a post published on a CPT from the front-end
- Extensive search filtering and results->PDF in the front-end
- Front end page submission form does not attach custom post type
- Issue with permalinks for custom post type
- Front end Submit not posting to Custom Post type
- Check in function on custom page
- create category upon saving post and save post in that category
- Front end post or photo or both
- How to get all taxonomies of a post type?
- Permalinks: custom post type -> custom taxonomy -> post
- Efficient Taxonomy Intersection
- How to create a wp_query that contains both meta_query and tax_query
- Extend walker class with custom post types [closed]
- Notice: map_meta_cap was called incorrectly
- How to have a custom URL structure for a custom post type?
- Custom post types and permalinks : What a mess !
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- Custom post type history
- Custom Taxonomy breaking pages permalinks
- Query Custom Post Types by date (custom field) range
- How to show custom post template from single page?
- Problem with custom post types, taxonomy and permalinks
- Custom post type table
- Remove visibility for custom post type
- Group CPT posts by custom taxonomy
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- How to display Related Posts based on number of taxonomy terms matched
- Get term name without a foreach loop
- Custom meta Title for custom post type archive from page
- Navigate posts with different post type that are in the same categories
- How do I add custom HTML to the content of an archive page’s posts?
- How to add query args to links to CPT admin submenu
- Templates for hierarchical custom post type
- Get post content from another section in custom single page
- Custom post type – change name in sidebar
- custom post type: own database table structure and custom “new-post” interface
- Custom Post Types and Complex Content Hierarchy
- Limit custom post type to the authors only on front-end!
- How to remove default modules on single event page on Modern Events Calendar
- Modify the category post counting function
- How to create new permission for custom post types for doing specific tasks
- Post navigation doesn’t show (in custom template, custom post type, custom query)
- Keep custom read more link on the same line as excerpt text
- Working with gallery shortcode and get gallery images
- Pagination with Custom Post Type
- Paginate yearly archives for a custom post type
- Why does wp_generate_uuid4() timeout?