Answers.Body: <p>Easy enough:</p>
  
  <pre><code>$query = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $query-&gt;section = 'mySection';
  $results = $query-&gt;find();
  </code></pre>
  
  <p>You can obviously refine the query before calling <code>find()</code>:</p>
  
  <pre><code>$query-&gt;limit   = null;
  $query-&gt;myCustomField = 'value';
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-11T10:09:15.003Z
Answers.Text: 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
Answers.UserDisplayName: uncle drew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-11T10:23:22.920Z
Answers.Text: Well, you can return json_encode($results). Maybe this can help: https://github.com/pixelandtonic/ElementAPI
Answers.UserDisplayName: gioppe
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-11T08:00:51.270Z
Answers.LastActivityDate: 2016-11-11T08:00:51.270Z
Answers.UserDisplayName: gioppe
Body: <p>Can you give an example of returning entries from a section in JSON format using a custom query? </p>
  
Tags: <plugin-development>
Title: How to create a custom query inside a plugin in Craft?
ThreadText: # How to create a custom query inside a plugin in Craft?
  
  (Asked by: username_0 on 2016-11-11)
  
  Can you give an example of returning entries from a section in JSON format using a custom query?
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-11. Score: 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';
  
  ```
  
  > **Comments:**
  > **username_0**: 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  
  > **username_1**: Well, you can return json_encode($results). Maybe this can help: https://github.com/pixelandtonic/ElementAPI  
  
  ---
  
  