Closed dqnguyen1989 closed 10 years ago
@dqnguyen1989 Absolutely, and I use QueryBuilder for this
$qb = $this->getEntityManager()->createQueryBuilder()
->from('KayueWordpressBundle:post', 'post')
->select('post, tax, term')
->leftJoin('post.taxonomies', 'tax')
->leftJoin('tax.term', 'term')
->andWhere('tax.name = :tax')
->andWhere('term.slug = :term')
->andWhere('post.type = \'post\'')
->andWhere('post.status = \'publish\'')
->setParameter('tax', $tax)
->setParameter('term', $slug);
@kayue : It excuted FatalErrorException Call to undefined method Bundle\Controller\DefaultController::getEntityManager().
I used namespace: use Kayue\WordpressBundle\Doctrine\WordpressEntityManager; use Kayue\WordpressBundle\Entity;
Thanks for helping.
Oops it is a private method of mind. Try to use $this->get('kayue_wordpress.post.manager')
(In fact Doctrine's default entity manager doctrine.orm.default_entity_manager
should work as well if you are in the same database and things are configured properly.)
Sorry but where can I find document for this bundle, I'm confused. And how to used functions listed on your README. Your bundle is great but I can't find document.
@dqnguyen1989 The read me should have everything. Which part is blocking you?
As long as your Symfony app is in the same database as the WordPress, all the entity should just work.
(WordPress Authentication is tricky but it should work too..)
OK, I'm cleared, but How can I getContent like apply_filters('the_content') on wordpress, i'm using php, not twig
The usage is exactly the same as normal entity $post->getContent()
, this will return the raw value from database.
To get format like normal WordPress (with p tags etc), you will need to use the wp_autop
filter.
wp_autop is twig function ? I'm using php for this.
@dqnguyen1989 Although it is a twig function, it is also a PHP function. You will need a way to access the WordpressExtension class. (or copy and paste this function to your app.)
https://github.com/kayue/KayueWordpressBundle/blob/master/Twig/Extension/WordpressExtension.php
I'm thank you your helping but I receive null data when I run
$qb = $this->get('doctrine.orm.default_entity_manager')->createQueryBuilder()
->from('KayueWordpressBundle:post', 'post')
->select('post, tax, term')
->leftJoin('post.taxonomies', 'tax')
->leftJoin('tax.term', 'term')
->andWhere('tax.name = :tax')
->andWhere('term.slug = :term')
->andWhere('post.type = \'post\'')
->andWhere('post.status = \'publish\'')
->setParameter('tax', $tax)
->setParameter('term', $slug);
That means no posts were found. Maybe try to remove all the where statements?
$qb = $this->get('doctrine.orm.default_entity_manager')->createQueryBuilder()
->from('KayueWordpressBundle:post', 'post')
->select('post')
->getQuery()->getResult()
@kayue : Thanks for all helping. It's run with this code
$posts = $this->get('doctrine.orm.default_entity_manager')->createQueryBuilder()
->from('KayueWordpressBundle:post', 'post')
->select('post')
->leftJoin('post.taxonomies', 'tax')
->leftJoin('tax.term', 'term')
->andWhere('tax.name = :tax')
->andWhere('term.slug = :term')
->andWhere('post.status = \'publish\'')
->setParameter('tax', 'category')
->setParameter('term', $category_slug)
->getQuery()->getResult();
@dqnguyen1989 Can you try the following see if it is returning any post? Just want to make sure the bundle is working.
$this->getDoctrine()->getRepository('KayueWordpressBundle:Post')->findOneById(1);
// or even return all posts!
$this->getDoctrine()->getRepository('KayueWordpressBundle:Post')->findAll();
If it works, then you can debug your query:
// build query builder...
var_dump($qb->getQuery()->getSql());
exit;
The bundle work correctly. Thanks :+1:
Good to hear that :+1:
Hi,
Can I get all post by desire term slug( eg:uncategorized ) ? I'm using Wordpress as backend and Symfony2 to get all data.
Thanks