Answers.Body: <p>Sounds like you're looking for a combination of the <code>orderBy</code> and <code>relatedTo</code> <a href="https://docs.craftcms.com/v3/element-query-params/entry-query-params.html" rel="nofollow noreferrer">entry query params</a>.</p>
  
  <p>This may put you on the right track?</p>
  
  <pre><code>{% set topThree = craft.entries({
    section: 'posts',
    relatedTo: { targetElement: myCategory },
    orderBy: 'myBudgetValueField desc',
    limit: 3
  }).all %}
  </code></pre>
  
  <p>Alternatively, for just the entry with the highest value:</p>
  
  <pre><code>{% set topFigure = craft.entries({
    section: 'posts',
    relatedTo: { targetElement: myCategory },
    orderBy: 'myBudgetValueField desc'
  }).one %}
  </code></pre>
  
  <p>Of course, this depends on <code>myBudgetValueField</code> being a number or some other easily-sortable value. If you need to format the value, I'd recommend storing it in the unit for comparison, and then visually treating it when you output it (i.e. store <code>300000</code>, even if you eventually need to output <code>$300,000</code>).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-14T19:46:53.330Z
Answers.LastActivityDate: 2018-06-14T19:46:53.330Z
Answers.UserDisplayName: August Miller
Body: <p>Each entry in <code>posts</code> has a field called <code>value</code>.  <code>Value</code> is a number.</p>
  
  <p><strong>For a <code>category</code>, how can I return the entry with the highest value?</strong></p>
  
  <p>This is not for Craft Commerce.  Value represents a budget figure.  </p>
  
  <p>Alternatively...</p>
  
  <p>How can I return the top 3 entries (based on value)?</p>
  
Tags: <templating>
Title: How can I return the entry with the highest value?
ThreadText: # How can I return the entry with the highest value?
  
  (Asked by: username_0 on 2018-06-14)
  
  Each entry in `posts` has a field called `value`. `Value` is a number.
  
  **For a `category`, how can I return the entry with the highest value?**
  
  This is not for Craft Commerce. Value represents a budget figure.
  
  Alternatively...
  
  How can I return the top 3 entries (based on value)?
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-06-14. Score: 1 | Accepted answer
  
  Sounds like you're looking for a combination of the `orderBy` and `relatedTo` [entry query params](https://docs.craftcms.com/v3/element-query-params/entry-query-params.html).
  
  This may put you on the right track?
  
  ```
  {% set topThree = craft.entries({
    section: 'posts',
    relatedTo: { targetElement: myCategory },
    orderBy: 'myBudgetValueField desc',
    limit: 3
  }).all %}
  
  ```
  
  Alternatively, for just the entry with the highest value:
  
  ```
  {% set topFigure = craft.entries({
    section: 'posts',
    relatedTo: { targetElement: myCategory },
    orderBy: 'myBudgetValueField desc'
  }).one %}
  
  ```
  
  Of course, this depends on `myBudgetValueField` being a number or some other easily-sortable value. If you need to format the value, I'd recommend storing it in the unit for comparison, and then visually treating it when you output it (i.e. store `300000`, even if you eventually need to output `$300,000`).
  
  
  ---
  
  