mbo2olivier / mukadi-wordpress-bundle

Integrate wordpress and symfony in the same application
21 stars 11 forks source link

ACF compatibility #2

Closed mnguye08 closed 6 years ago

mnguye08 commented 6 years ago

Hi @mbo2olivier As discussed before, I'm trying to implement Wordpress and Symfony using your bundle. For now, with the code below, I have the Post object

$crud = new CRUD($this->getDoctrine()->getManager(), Post::class);
var_dump($crud->get(1));

But the custom fields created with WP ACF plugin aren't retrieved. Do you know if it's possible and if yes, how?

Thanks Kind regards

mbo2olivier commented 6 years ago

Hi @mnguye08

Sorry for this late response.

If you just want to retreive a postMeta relative to a given Post, you can use the default PostMeta repository, there is a method that will allow you to do it easily. From Doctrine EntityManager the code will look like:

$q= $em->getRepository(PostMeta::class)->getPostMetaQuery($postId,$metaKey); $metas = $q->getResult();

this method return an array of PostMeta, $postId is the Id of the Post and $metaKey is the key.

I hope this little comment will have helped you. Do not hesitate to come back to me if needed. Kind Regards.

mnguye08 commented 6 years ago

Hi @mbo2olivier

Thanks a lot for your feedback. I've tested the method and it works! However, I have an image custom field. The retrieved value is the post ID (even if I've set the whole object in ACF). Do you know if it's possible to get the URL value without making an other query?

Thanks again for your work! Kind regards

mbo2olivier commented 6 years ago

Hi @mnguye08

The retrieved value is the post ID

What ID is it? the one you sent to the getPostMetaQuery method or the attachment one ? If it's about the attachement Id, so the best way to fetch this information is to override the default repository (or simply create a service) and write a method that retrieves the image object based on the Post id, the meta key and and the returned attachment Id. The query must be based on how ACF save its information in WP DB schema.

as soon as I have time I will write an addons for ACF support.

mnguye08 commented 6 years ago

OK thanks. I'll try it. I close the issue.