kayue / KayueWordpressBundle

A Symfony 2 bundle for providing WordPress repositories and authenticating users (login).
101 stars 43 forks source link

Using createQueryBuilder with Blog id #31

Closed dqnguyen1989 closed 10 years ago

dqnguyen1989 commented 10 years ago

Hi Kayue, I'm using this code to load term by it's parent id

$posts =$this->em->createQueryBuilder()
            ->from('KayueWordpressBundle:Taxonomy', 'tax')
            ->select('tax')
            ->leftJoin('tax.term', 'term')
            ->andWhere('tax.name = :tax')
            ->andWhere('tax.parent=:parent')
            ->setParameter('tax', 'category')
            ->setParameter('parent', $parent_id)
            ->getQuery()->getResult();

Can I using this code to get data from multisite blog? I want to do more work with your bundle, thanks.

kayue commented 10 years ago

Try to retrive entity manager via kayue_wordpress.blog.manage service first:

$blogManager = $this->get('kayue_wordpress.blog.manager');
$em = $blogManager->findBlogById(3)->getEntityManager();
$posts = $em->createQueryBuilder(); // do your query here
dqnguyen1989 commented 10 years ago

Thanks Kayue. It's working fine.