0

Can you give an example of returning entries from a section in JSON format using a custom query?

2

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';
|improve this answer|||||
  • 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 – uncle drew Nov 11 '16 at 10:09
  • 1
    Well, you can return json_encode($results). Maybe this can help: github.com/pixelandtonic/ElementAPI – gioppe Nov 11 '16 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.