Filtering by tag

To discover a more advanced use of the QueryBuilder and DQL, we will create a list of posts having one or more tags.

Tag filtering is good for Search Engine Optimization and allows the readers to easily find the content they are interested in. We will build a system that is able to list posts that have several tags in common; for example, all the posts tagged with Doctrine and Symfony.

To filter our posts using tags kindly perform the following steps:

  1. Add another method to our custom PostRepository class (src/Blog/Entity/PostRepository.php) using the following code:
     /** * Finds posts having tags * * @param string[] $tagNames * @return Post[] */ public function findHavingTags(array $tagNames) { return $queryBuilder = $this ->createQueryBuilder('p') ...

Get Persistence in PHP with Doctrine ORM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.