Find a post by slug.

@param string $slug         the slug of the post
@param string $postTypeSlug the name of the post type, ex. post_services

@return object|null Returns post as array or null if not found
507987
public static function findBySlug($slug, $postTypeSlug = '')
    {
        $postTypeSlug = ($postTypeSlug ? $postTypeSlug : PostType::getSlug());

        $postObj = (new Post())->setTable($postTypeSlug);
        $post = $postObj
            ->where('slug_'.App::getLocale(), $slug)
            ->with($postObj->getDefaultRelations(getPostType($postTypeSlug)))
            ->first();

        return $post;
    }
685982
public function getBySlug($sSlug)
    {
        foreach ($this->aComponents as $oComponent) {
            if ($sSlug == $oComponent->slug) {
                return $oComponent;
            }
        }

        return null;
    }
878928
public function getPlugin($slug)
    {
        $this->plugins->rewind();
        while ($this->plugins->valid()) {
            if ($this->plugins->current()->getSlug() == $slug) {
                return $this->plugins->current();
            }
            $this->plugins->next();
        }

        return false;
    }
869919
public function view($slug = null)
    {
        //Data can be passed as query string, from a widget
        if ($this->request->getQuery('q')) {
            return $this->redirect([$this->request->getQuery('q')]);
        }

        $slug = Text::slug($slug, ['replacement' => ' ']);

        $tag = $this->PostsTags->Tags->findActiveByTag($slug)
            ->cache((sprintf('tag_%s', md5($slug))), $this->PostsTags->getCacheName())
            ->firstOrFail();

        $page = $this->request->getQuery('page', 1);

        //Sets the cache name
        $cache = sprintf('tag_%s_limit_%s_page_%s', md5($slug), $this->paginate['limit'], $page);

        //Tries to get data from the cache
        list($posts, $paging) = array_values(Cache::readMany(
            [$cache, sprintf('%s_paging', $cache)],
            $this->PostsTags->getCacheName()
        ));

        //If the data are not available from the cache
        if (empty($posts) || empty($paging)) {
            $query = $this->PostsTags->Posts->find('active')
                ->find('forIndex')
                ->matching($this->PostsTags->Tags->getAlias(), function (Query $q) use ($slug) {
                    return $q->where(['tag' => $slug]);
                });
            $posts = $this->paginate($query);

            //Writes on cache
            Cache::writeMany([
                $cache => $posts,
                sprintf('%s_paging', $cache) => $this->request->getParam('paging'),
            ], $this->PostsTags->getCacheName());
        //Else, sets the paging parameter
        } else {
            $this->request = $this->request->withParam('paging', $paging);
        }

        $this->set(compact('posts', 'tag'));
    }
618472
public static function findByThemeId( $slug, $type, $themeId ) {

		return self::queryBySlugType( $slug, $type, [ 'ignoreSite' => true ] )->andWhere( 'themeId=:themeId', [ ':themeId' => $themeId ] )->one();
	}
1018038
public function findBySlug($slug)
    {
        $qb = $this->createQueryBuilder('p');

        $currentTime = new \DateTime();

        $qb->select('p')
            ->where(
                $qb->expr()->lt('p.publicationAt', ':datetime')
            )
            ->andWhere('p.enabled = 1')
            ->andWhere('p.slug = :slug')
            ->orderBy('p.publicationAt', 'DESC')
            ->setMaxResults(1);

        $qb->setParameter(':datetime', $currentTime);
        $qb->setParameter(':slug', $slug);

        $result = $qb->getQuery()->getResult();

        if ($result) {
            return $result[0];
        }

        return null;
    }
156614
public static function validatePostType($postTypeSlug = '')
    {
        if(!$postTypeSlug) {
            $postTypeSlug = \Request::route('postTypeSlug');
        }
        return ($postTypeSlug && !PostType::findBySlug($postTypeSlug));
    }
117747
public function getPostTypeObject($post_type)
    {
        if ( ! isset($this->postTypes[ $post_type ])) {
            return false;
        }

        return $this->postTypes[ $post_type ];
    }
784962
public static function findBySlug($slug,$languageSlug = "")
    {
        $getMenuLink = array_where(
            MenuLink::all(), function ($value) use ($slug) {
                return ($value['slug'] == $slug);
            }
        );

        if($getMenuLink) {
            return array_first($getMenuLink);
        }
        return false;
    }
570067
public function view($slug = null)
    {
        $post = $this->Posts->findActiveBySlug($slug)
            ->find('forIndex')
            ->cache(sprintf('view_%s', md5($slug)), $this->Posts->getCacheName())
            ->firstOrFail();

        $this->set(compact('post'));

        //Gets related posts
        if (getConfig('post.related')) {
            $related = $this->Posts->getRelated($post, getConfigOrFail('post.related.limit'), getConfig('post.related.images'));
            $this->set(compact('related'));
        }
    }
933922
public function getBySlug($lang, $slug)
    {
        $postType = PostType::collection()->where('slug', $slug);
        if(!$postType->isEmpty()) {
            return $postType->first();
        }
        return [];
    }
950940
public function getAllWithoutPaginationByPostType($lang = "", $postType = "")
    {
        return DB::table('tags')->join('post_type', 'post_type.postTypeID', 'tags.postTypeID')->where('post_type.slug', $postType)->orderBy('name', 'postTypeID')->get();
    }
1168559
public function view($slug = null)
    {
        //The category can be passed as query string, from a widget
        if ($this->request->getQuery('q')) {
            return $this->redirect([$this->request->getQuery('q')]);
        }

        $category = $this->PagesCategories->findActiveBySlug($slug)
            ->select(['id', 'title'])
            ->contain($this->PagesCategories->Pages->getAlias(), function (Query $q) {
                return $q->find('active')->select(['category_id', 'slug', 'title']);
            })
            ->cache(sprintf('category_%s', md5($slug)), $this->PagesCategories->getCacheName())
            ->firstOrFail();

        $this->set(compact('category'));
    }
1022949
public function get($slug){
        return empty($this->index[$slug]) ? null : $this->index[$slug];
    }
609186
public function findOneBySlug($slug)
    {
        $query = $this->createValuedQueryBuilder('c')
            ->where('c.slug = :slug')
            ->setParameter('slug', $slug)
            ->getQuery();

        return $query->useResultCache(true, self::CACHE_TTL)->getSingleResult();
    }
738287
static function getForm ($slug)
    {
        foreach (self::$forms as $form)
            /* @var $form Form */
            if ($form->getGlobalSlug() == $slug)
                return $form;
        return null;
    }
1371965
public function bySlug($slug, $attributes = ['*'])
    {
        if (!request('preview')) {
            $this->published();
        }
        $model = $this->findBy(column('slug'), $slug, $attributes);

        if (is_null($model)) {
            abort(404);
        }

        return $model;
    }