Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » get_by_stage HELP

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 204 Views
  • cachobong
    Avatar
    Community Member
    9 Posts

    get_by_stage HELP Link to this post

    i got some records using the below code.

    $liveRecords = Versioned::get_by_stage('MyRecord', 'Live');

    assuming that i don't know the IDs for the records, how do i scan through the records to check their titles to get the one that i want then return this record for it to act like a "get_one_by_stage"

    Please help!

    Thanks

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: get_by_stage HELP Link to this post

    Assuming you're running 3.0, you can just use:

    return Versioned::get_by_stage('MyRecord', 'Live')->filter('Title', 'MyTitle')->First();

  • cachobong
    Avatar
    Community Member
    9 Posts

    Re: get_by_stage HELP Link to this post

    I'm on 2.4. Is there any way it could be like that in 2.4? I cannot upgrade the version since i'm not the site owner.

    204 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.