I am attempting to get a specific entries id from within a specific section. I have looked around, and clearly have not found anything yet.

To clarify, lets say we have a section called "Stories", which is a structure. Inside of "Stories" there is a specific entry named, "Story One" that I would like to retrieve the id of.

I can pretty much get as far as getting the contents of the Stories structure via:

$entry = craft()->sections->getSectionByHandle('stories');

The important piece here, is that I want to find the "Story One" entry id. Reason being is that it looks like you can't do relatedTo queries via the title of an entry, but you need the id.


Correct me if iam wrong but cant you just use the ElementCriteriaModel. Essentially because you are looking for an element type using that will give you much more flexibility - bassicly it is a query builder on roids.

    $criteria = craft()->elements->getCriteria(ElementType::Entry);

    // Enter in params. here you can enter your sectionId
    $criteria->section = 'stories';
    $criteria->title   = 'Story One';
    $entries = $criteria->find();

This will return an array of all the entries that match this criteria. Ofcourse because this is craft you can thus enter a whole lot of other params and do some fancy stuff e.t.c..

I'll add two links at the bottom that are good reads on the subject:



  • Will give this a shot tomorrow at work. Ill mark it as correct if it works. Mar 25 '18 at 18:36
  • 1
    Winner winner, chicken dinner. Thanks for the help! Mar 26 '18 at 11:15
  • Glad i could help! Good luck with the project :)! Mar 26 '18 at 13:05

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.