<p>You've got a couple of incorrect things going on in your current example.</p>

<p>Calling <code>craft()-&gt;elements-&gt;getCriteria(ElementType::Entry)</code> returns an <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel" rel="nofollow">ElementCriteriaModel</a>.</p>

<p>That's what you want to set the parameters on for the entries you're searching for. Stuart sums it up well <a href="https://craftcms.stackexchange.com/questions/265/what-are-the-differences-between-an-elementcriteriamodel-and-fetched-elements">here</a>.</p>

<p>By calling <code>-&gt;first()</code> on it immediately, you're going to get the defaults, which for entries is by post date in descending order.</p>

<p>By calling:</p>

<pre><code>$entry-&gt;slug = $page;
echo $entry-&gt;title;
</code></pre>

<p>You are actually updating the slug for the entry that was returned to be something new.</p>

<p>This should work for what you're trying to do:</p>

<pre><code>    $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
    $criteria-&gt;slug = 'about';
    $criteria-&gt;section = 'news';
    $entry = $criteria-&gt;first();
    $title = $entry-&gt;title;
</code></pre>

CC BY-SA 3.0
2015-08-21T08:15:34.520Z
Thanks Brad [again]. I realised calling ->first() was the start of my problems, I realise now I overlooked some fairly basic formatting/syntax issues too. Works like a charm.
Mark Notton
CC BY-SA 3.0
2015-08-20T18:19:02.700Z
2015-08-20T18:47:08.047Z
2015-08-20T18:47:08.047Z
Brad Bell
<p>I can do the following to pull out the page title after parsing in just the page slug:</p>

<pre><code>$page = 'about';
$entry = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry)-&gt;first();
$entry-&gt;slug = $page;
echo $entry-&gt;title;
</code></pre>

<p>(I understand this is overkill, but an answer to this question will help me answer further questions I dare not try to explain here). </p>

<p>The problem is, the slug doesn't need to be unique if other sections/channels/singles use the same name, and the method above only calls out the first instance of "about". </p>

<p><strong>How can I define what section is being referred to?</strong></p>

<p>This will update the handle, but has no effect on the output:</p>

<pre><code>$entry-&gt;section-&gt;handle = "pages";
</code></pre>

<p>This returns a Read Only error: </p>

<pre><code>$entry-&gt;section = "Pages"
</code></pre>

<blockquote>
  <p>Property "Craft\EntryModel.section" is read only.</p>
</blockquote>

<plugin-development>
Refer to specific section handle when querying an element by 'getCriteria'
# Refer to specific section handle when querying an element by 'getCriteria'

(Asked by: username_0 on 2015-08-20)

I can do the following to pull out the page title after parsing in just the page slug:
$page = 'about';
$entry = craft()->elements->getCriteria(ElementType::Entry)->first();
$entry->slug = $page;
echo $entry->title;

(I understand this is overkill, but an answer to this question will help me answer further questions I dare not try to explain here). 
The problem is, the slug doesn't need to be unique if other sections/channels/singles use the same name, and the method above only calls out the first instance of "about". 
How can I define what section is being referred to?
This will update the handle, but has no effect on the output:
$entry->section->handle = "pages";

This returns a Read Only error: 
$entry->section = "Pages"


Property "Craft\EntryModel.section" is read only.

**Tags:** plugin-development

---

## 1 answers

### Answer by username_1 on 2015-08-20. Score: 1 | Accepted answer

You've got a couple of incorrect things going on in your current example.
Calling craft()->elements->getCriteria(ElementType::Entry) returns an ElementCriteriaModel.
That's what you want to set the parameters on for the entries you're searching for. Stuart sums it up well here.
By calling ->first() on it immediately, you're going to get the defaults, which for entries is by post date in descending order.
By calling:
$entry->slug = $page;
echo $entry->title;

You are actually updating the slug for the entry that was returned to be something new.
This should work for what you're trying to do:
    $criteria = craft()->elements->getCriteria(ElementType::Entry);
    $criteria->slug = 'about';
    $criteria->section = 'news';
    $entry = $criteria->first();
    $title = $entry->title;

> **Comments:**
> **username_0**: Thanks Brad [again]. I realised calling ->first() was the start of my problems, I realise now I overlooked some fairly basic formatting/syntax issues too. Works like a charm.  

---

