3

I've noticed something odd and I can't find anything in the documentation.

I'm writing a plugin and when I use ElementCriteriaModel to find an existing entry like so:

$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'entryHandle';
$criteria->title = 'The Title & Stuff';
$existingEntry = $criteria->first();

The entry is not found, and I believe it's because of the punctuation. The entry is clearly in the craft_content table (with the exact title including punctuation). Is there some sort of processing I need to do before setting the title criterion?

Thanks!

  • 1
    Which character set and collation is your database using? – Steve Adams Aug 15 '15 at 3:00
  • character set: UTF 8, collation: utf8_unicode_ci – ashley Aug 15 '15 at 3:03
  • 2
    You might need to treat the ampersand as a special character. Try this and see what happens: $criteria->title =escapeParam("The Title & Stuff"); Just an untested guess. – Steve Adams Aug 15 '15 at 3:25
1

I've tested your code with a similar query in a local database and am getting the results you'd expect. So the code seems accurate. Aside from environmental variables that may be at play, the only part of the example code above that I see a potential issue with the line:

$criteria->section = 'entryHandle'; 

It's unclear what you may mean by entryHandle. This value should be the sectionHandle. If entryHandle means slug, then the $criteria->section may need to get updated to be $criteria->slug = 'entryHandle';

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.