0

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

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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