Can you give an example of returning entries from a section in JSON format using a custom query?
1 Answer
Easy enough:
$query = craft()->elements->getCriteria(ElementType::Entry);
$query->section = 'mySection';
$results = $query->find();
You can obviously refine the query before calling find()
:
$query->limit = null;
$query->myCustomField = 'value';
-
Thanks for your answer, but i want to "json encode" the result so that i can use it in my javascript , its hard for me to convert the result using elements criteria is there a way that i can only get the results in json format Commented Nov 11, 2016 at 10:09
-
1Well, you can return json_encode($results). Maybe this can help: github.com/pixelandtonic/ElementAPI– gioppeCommented Nov 11, 2016 at 10:23