ekino / EkinoWordpressBundle

Integrate Symfony with WordPress and WordPress with Symfony
GNU General Public License v2.0
311 stars 79 forks source link

Repository ekino.wordpress.manager.post #104

Closed yzaouga closed 8 years ago

yzaouga commented 8 years ago

I try to get posts with filtred post_type. this is my code:

config.yml ekino_wordpress: table_prefix: "wp_" # If you have a specific Wordpress table prefix load_twig_extension: true # If you want to enable native WordPress functions (ie : get_option() => wp_get_option()) enable_wordpress_listener: false # If you want to disable the WordPress request listener services: post: repository_class: TestBundle\Entity\PostsRepository

TestBundle\Entity\PostsRepository.php <?php

namespace TestBundle\Entity;

/** * PostsRepository * * This class was generated by the Doctrine ORM. Add your own custom * repository methods below. */ class PostsRepository extends \Doctrine\ORM\EntityRepository { public function getPostByType($type) { $qb = $this->createQueryBuilder('p') ->where('p.post_type = :type') ->setParameter('type', $type) ; $result = $qb->getQuery()->getResult(); return $result; } }

Controller.php public function indexAction() { $postManager = $this->get('ekino.wordpress.manager.post'); $post = $postManager->getPostByType('post'); return $this->render('TestBundle:Default:index.html.twig', array('posts' => $post)); }

Attempted to call method "getPostByType" on class "Ekino\WordpressBundle\Manager\PostManager".

eko commented 8 years ago

Hi @yzaouga,

You can override any manager by creating a new PostManager into your code and declaring a service for it.

When it's done, you just have to tell on the bundle configuration that you want to use it for the PostManager, this way:

ekino_wordpress:
    services:
        post:
            manager: my_custom_post_manager_service

I'm closing this issue, please feel free to reopen if it is still relevant.