Get selected categories of a single post.

@param  int    $id
@param  string $postTypeSlug
@return array
428396
private function getPostSelectedCategories($id, $postTypeSlug)
    {
        // get the selected categories from the DB table categories_relations
        $categoryRelationTable = $postTypeSlug.'_categories';
        $selectedCategories = DB::table($categoryRelationTable)
            ->leftJoin('categories', $categoryRelationTable.'.categoryID', 'categories.categoryID')
            ->where($categoryRelationTable.'.postID', $id)
            ->select("categories.categoryID", "categories.postTypeID", "categories.title", "categories.slug")
            ->get();

        return Language::filterRows($selectedCategories, false);
    }
915147
public function categoryList($site_id)
    {
        $response = $this->getGuzzleClient()
            ->get('/sites/' . $site_id . '/categories', $this->setQuery());

        return $this->serializer->deserialize(
            $response->getBody()->getContents(),
            "array<" . Category::class . ">",
            'json'
        );
    }
1300513
private function getSearchableCategories($storeId, $categoryIds = null, $fromId = 0, $limit = 100)
    {
        return $this->resourceModel->getSearchableCategories($storeId, $categoryIds, $fromId, $limit);
    }
930107
public function getSearchableCategories($storeId, $categoryIds = null, $fromId = 0, $limit = 100)
    {
        /**
         * @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection
         */
        $categoryCollection = $this->categoryCollectionFactory->create();
        $categoryCollection->addIsActiveFilter();
        $select = $categoryCollection->getSelect();

        $this->addIsVisibleInStoreFilter($select, $storeId);

        if ($categoryIds !== null) {
            $select->where('e.entity_id IN (?)', $categoryIds);
        }

        $select->where('e.entity_id > ?', $fromId)
            ->limit($limit)
            ->order('e.entity_id');

        return $this->connection->fetchAll($select);
    }
564665
public function getByApp($lang, $module, $formType, $id, $postType = "")
    {
        return CustomFieldGroup::findGroups($module, $formType, $id, $postType);
    }
1117924
public function getInTableColumns($postType)
    {
        $inTableColumnsSlugs = [];
        $fields = PostType::getFields($postType);

        // default columns
        foreach(Post::$defaultListColumns as $key => $label){
            if(substr($label, 0, 2) == '__') {
                $label = __(substr($label, 2));
            }

            $inTableColumnsSlugs[$key] = $label;
        }

        // post type columns
        foreach($fields as $field){
            if($field->inTable) {
                $inTableColumnsSlugs[$field->slug] = $field->name;
            }
        }

        // custom events columns
        $customListColumms = Event::fire('post:table_list_columns', [$postType]);
        foreach($customListColumms as $customList){
            if(is_array($customList)) {
                foreach ($customList as $key => $value) {
                    $inTableColumnsSlugs[$key] = $value;
                }
            }
        }
        return $inTableColumnsSlugs;
    }
491439
public function exportById($id): array
    {
        $categoryGroup = Craft::$app->categories->getGroupById((int) $id);

        return $this->export($categoryGroup);
    }
441801
public function getAllByPostType($lang = "", $postTypeID)
    {
        $orderBy = (isset($_GET['order'])) ? $orderBy = $_GET['order'] : 'tagID';
        $orderType = (isset($_GET['type'])) ? $orderType = $_GET['type'] : 'DESC';
        // get data
        return Tag::where('postTypeID', $postTypeID)->orderBy($orderBy, $orderType)->paginate(Tag::$rowsPerPage);
    }
1031555
protected function getCategory($id)
    {
        $category = $this->categoryManager->find($id);

        if (null === $category) {
            throw new NotFoundHttpException(sprintf('Category (%d) not found', $id));
        }

        return $category;
    }
975230
function getCategory($id)
    {
        $result = $this->db->query('SELECT * FROM category WHERE id = :id', [':id'=>(0+$id)]);
        if (isset($result[0])) {
            return ['name'=>$result[0]->get('name'),
                'description'=>$result[0]->get('description')];
        }
        return false;
    }
1254341
public function getFrontMatterType( $id ) {

		$terms = get_the_terms( $id, 'front-matter-type' );
		if ( $terms && ! is_wp_error( $terms ) ) {
			foreach ( $terms as $term ) {
				return $term->slug;
			}
		}

		return 'miscellaneous';
	}
108159
private function deletePostType($id)
    {
        $postType = PostType::find($id);
        if(!$postType) {
            return false;
        }

        // Check if this post type has posts
        // Post type should not be able to be deleted if it has posts
        if(PostType::hasPosts($postType->slug) || PostType::isInMenuLinks($id)) {
            return $this->response("You can't delete this Post Type. There could be posts associated with it or it is part of a menu", 403);
        }

        if($this->deleteRelatedTagsAndCategory($postType) && $postType->delete()) {
            Schema::drop($postType->slug);

            // delete route file
            if(file_exists(base_path().'/routes/'.$postType->slug.'.php')) {
                unlink(base_path() . '/routes/' . $postType->slug . '.php');
            }
            return true;
        }

        return false;
    }
284173
public function getAllForTimelogCategory(string $id, array $params = [])
    {
        return $this->executeRequest(
            RequestMethodEnum::GET,
            ResourceMethodEnum::GET_ALL_FOR_TIMELOG_CATEGORY,
            $params,
            $id
        );
    }
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;
    }
1135415
public static function delete_category($id) {
        $category = new category($id);
        if ($category->is_used()) {
            throw new \moodle_exception('Category with id ' . $id . ' can not be deleted because it is used.');
        }
        return $category->delete();
    }
1360061
final protected function getCategory($id, $default = null)
    {
        if ($id instanceof CategoryInterface) {
            return $id;
        }

        if (is_numeric($id)) {
            return $this->categoryManager->find($id);
        }

        if ($default instanceof CategoryInterface) {
            return $default;
        }

        return null;
    }
1023273
public function getShortcodeModules($post_id) : array
    {
        $post = get_post($post_id);
        $pattern = get_shortcode_regex();
        $modules = array();

        if (is_object($post) && preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches)
            && array_key_exists(2, $matches)
            && in_array('modularity', $matches[2])) {

            $shortcodes = preg_replace('/[^0-9]/', '', $matches[3]);
            foreach ($shortcodes as $key => $shortcode) {
                $modules[] = array(
                    'ID' => $shortcode,
                    'post_type' => get_post_type($shortcode)
                );
            }
        }

        return $modules;
    }