Delete a single post and all his relation data (related tags and categories).

@param  int    $id
@param  string $postType
@return array|bool
435886
private function deletePost($id, $postType)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess($postType, 'delete', $id, true)) {
            return $this->noPermission();
        }

        // Check if this post type has posts
        // Post type should not be able to be deleted if it has posts
        if(Post::isInMenuLinks($id, $postType)) {
            return $this->response("You can't delete this Post because It is being used in menu links", 403);
        }

        $post = (new Post())->setTable($postType);
        $post = $post->find($id);

        if(!$post) {
            // create delete task
            Task::create('post', 'delete', [$id], ['postType' => $postType]);
            return $this->response('Post doesn\'n exist in the database. If it exist in archive, it will be deleted after 10 min.', 500);
        }

        if ($post->delete()) {
            // Delete categories relations of this post
            DB::table(categoriesRelationTable($postType))->where('postID', $id)->delete();
            // Delete tags relations of this post
            DB::table(tagsRelationTable($postType))->where('postID', $id)->delete();
            return true;
        }
        return false;
    }
1345420
protected function _post($id = null)
    {
        $subject = $this->_subject();
        $subject->set(['id' => $id]);

        $entity = $this->_findRecord($id, $subject);

        $event = $this->_trigger('beforeDelete', $subject);
        if ($event->isStopped()) {
            return $this->_stopped($subject);
        }

        $method = $this->getConfig('deleteMethod');
        if ($this->_table()->$method($entity)) {
            $this->_success($subject);
        } else {
            $this->_error($subject);
        }

        return $this->_redirect($subject, ['action' => 'index']);
    }
1273590
protected function _deleteObject( $post_id ) {
		$post = get_post( $post_id );
		if ( ! $post ) {
			return false;
		}

		$deleted = wp_delete_post( $post_id, true );
		if ( $deleted ) {
			$this->_debug( 'Deleted post with ID: ' . $post_id );
			return true;
		}

		$this->_debug( 'Post removal failed for ID: ' . $post_id );
		return false;
	}
597153
public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);

        $album = $this->PhotosAlbums->get($id);

        //Before deleting, it checks if the album has some photos
        if (!$album->photo_count) {
            $this->PhotosAlbums->deleteOrFail($album);
            $this->Flash->success(I18N_OPERATION_OK);
        } else {
            $this->Flash->alert(I18N_BEFORE_DELETE);
        }

        return $this->redirect(['action' => 'index']);
    }
325700
public function delete($id)
    {
        $query = $this->createQueryBuilder();

        $query->where($this->getPrimaryKey($query), $id);
        $query->delete();
    }
703112
protected function __delete($index, $type, $id, array $parameters = []) {
        $result = $this->client->delete([
            'index' => $index,
            'type' => $type,
            'id' => $id] + $parameters);
        return $result;
    }
354170
public function postIdOfPostupdate($id)
    {
        // $record is a stdClass
        $record = DB::table('postupdates')
            ->select('post_id')
            ->where('id', '=', $id)
            ->first()
        ;

        return $record->post_id;
    }
390480
public function delete($lang, $id)
    {
        if(!User::hasAccess('Language', 'delete')) {
            return $this->noPermission();
        }
        $language = Language::find($id);

        if($language) {
            if ($language->isDefault) {
                return $this->response("You can't delete the default language!", 403);
            }

            if($language->delete()) {
                // create virutal column for slug of every post type in the created language
                $allPostTypes = PostType::all();
                foreach ($allPostTypes as $postType){
                    AccioQuery::deleteColumn($postType->slug, "slug_".$language->slug);
                }

                $this->deleteDirectory($language->slug);
                return $this->response('The Language was deleted');
            }
        }

        return $this->response('The Language was not deleted. Please try again later', 500);
    }
319832
public function delete($id = null)
    {
        $result = parent::delete($id);

        $this->handler->setBuilder($this)
            ->invalidateQuery(Reflector::QUERY_TYPE_DELETE, [Reflector::PRIMARY_KEY_COLUMN => $id]);

        return $result;
    }
92
public static function clearCache($postId, $post)
    {
        if (wp_is_post_revision($postId) || get_post_status($postId) != 'publish') {
            return false;
        }

        wp_cache_delete($postId, self::getKeyGroup());
        wp_cache_delete($post->post_type, self::getKeyGroup());

        // Empty post type for all sites in network (?)
        if (function_exists('is_multisite') && is_multisite() && apply_filters('Municipio\Cache\EmptyForAllBlogs', false, $post)) {
            $blogs = get_sites();

            foreach ($blogs as $blog) {
                wp_cache_delete($post->post_type, self::getKeyGroup($blog->blog_id));
            }
        }

        return true;
    }
1261444
public function delete_post( $id ) {

		$post = get_post( $id );

		if ( empty( $post ) ) {
			return;
		}

		$id        = $post->ID;
		$post_type = $post->post_type;

		return $this->delete_object( 'post_type', $id, $post_type );
	}
597230
private function deleteCategory(int $id)
    {
        $category = Category::find($id);
        if($category) {
            $postType = PostType::findByID($category->postTypeID);
            if(Category::isInMenuLinks($id)) {
                return $this->response("You can't delete this Category. It is part of a menu", 403);
            }

            // delete children
            $category->deleteChildren($category->categoryID, $postType->postTypeID);

            // delete relations
            DB::table(categoriesRelationTable($postType->slug))->where("categoryID", $category->categoryID)->delete();

            // Delete the item
            if($category->delete()) {
                return true;
            }
        }
        return false;
    }
281599
public function delete($type = null, $id = null)
    {
        $this->_validateActionIsEnabled('delete');

        $this->_event('beforeDelete', [
            'id' => $id
        ]);

        $entity = $this->Model->get($id);

        $this->request->allowMethod(['post', 'delete']);

        if ($this->Model->delete($entity)) {
            $this->Flash->success(__d('CakeAdmin', 'The {0} has been deleted.', [$this->type['singularAliasLc']]));
        } else {
            $this->Flash->error(__d('CakeAdmin', 'The {0} could not be deleted. Please, try again.', [$this->type['singularAliasLc']]));
        }

        $this->_event('afterDelete', [
            'id' => $id
        ]);

        return $this->redirect(['action' => 'index', 'type' => $this->type['name']]);
    }
967340
protected function deleteEntityLink($id)
    {
        $post = $this->repository->find($id);

        $this->manager->remove($post);
        $this->manager->flush();
    }
1213770
private function getPostRelatedMedia($id, $post, $postTypeSlug, $translatableFields)
    {
        $media = array();

        $mediaRelationTable = $postTypeSlug.'_media';
        // get the media relation joining the media table and the post
        $mediaRelationsResults = DB::table($mediaRelationTable)
            ->join('media', $mediaRelationTable.'.mediaID', 'media.mediaID')
            ->join($postTypeSlug, $mediaRelationTable.'.postID', $postTypeSlug.'.postID')
            ->where($mediaRelationTable.".postID", $id)
            ->select(
                'media.title as title', 'media.mediaID', $mediaRelationTable.'.mediaRelationID',
                $mediaRelationTable.'.postID', $mediaRelationTable.'.language',
                'media.description', 'media.credit', 'media.type', 'media.extension',
                'media.url', 'media.filename', 'media.fileDirectory', 'media.filesize', 'media.dimensions', $mediaRelationTable.'.field'
            )
            ->get();


        // the object media used for the media custom fields in the front end
        if ($post->featuredImageID) {
            $featuredImage = Media::find($post->featuredImageID);
            // set feature image if it exist
            if($featuredImage) {
                $media["featuredImage"][] = $featuredImage;
            }
        }
        if ($post->featuredVideoID) {
            $featuredVideo = Media::find($post->featuredVideoID);
            $media["featuredVideo"][] = $featuredVideo;
        }

        // loop throw the media relation and construct the $media object
        foreach ($mediaRelationsResults as $relation){
            if(in_array($relation->field, $translatableFields)) {
                $langArr = json_decode($relation->language);
                foreach ($langArr as $langKey => $lang){
                    if(!isset($media[$relation->field."__lang__".$langKey])) {
                        $media[$relation->field."__lang__".$langKey] = array();
                    }
                    if ($lang) {
                        array_push($media[$relation->field."__lang__".$langKey], $relation);
                    }
                }
            }else{
                if(!isset($media[$relation->field])) {
                    $media[$relation->field] = array();
                }
                array_push($media[$relation->field], $relation);
            }
        }

        return $media;
    }
948146
public function delete_data( $post_id ) {
		$table = $this->get_related_table_name();
		$this->delete_misc( $post_id );

		return $this->app->db->delete( $table, [
			'post_id' => $post_id,
		] );
	}
857627
public function actionDelete($id)
    {
        $model = $this->findModel($id);
        if ($model->deleteWithRelated()) {
            delete_seo_data($model->product_type, $model->primaryKey);
            Meta::deleteAll([
                'obj_type' => $model->product_type,
                'obj_id'   => $model->primaryKey,
            ]);
            TermRelationships::deleteAll([
                'obj_type' => $model->product_type,
                'obj_id'   => $model->primaryKey,
            ]);
            set_flash_success_delete_content();
        } else {
            set_flash_error_delete_content();
        }

        return $this->goBack(request()->referrer);
    }