We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How to get a custom field's value in PHP for a specific entry?

How Do I?

Felix Edward Todd's avatar
Felix Edward Todd
2 posts
3 years ago
Felix Edward Todd's avatar Felix Edward Todd

Let’s say I have an entry with ID “123” and I need to get the value of a custom field with shortname “custom_field.”

In ExpressionEngine, I know I can use the {exp:channel:entries} tag, but I need to do it via PHP.

       
USC Chan's avatar
USC Chan
81 posts
3 years ago
USC Chan's avatar USC Chan

You can use the ChannelEntry model pretty easily for this:

$entry_id = 123;

$entry_object = ee('Model')
                ->get('ChannelEntry')
                ->filter('entry_id', $entry_id)
                ->first();

$field_data = $entry_object -> field_id_5;

where the custom field you’re looking for in this case has an ID of #5. These examples taken from https://docs.expressionengine.com/latest/development/models/channel-entry.html

? 1
       
Felix Edward Todd's avatar
Felix Edward Todd
2 posts
3 years ago
Felix Edward Todd's avatar Felix Edward Todd

Thank you very much!

       
Jemis's avatar
Jemis
1 posts
2 years ago
Jemis's avatar Jemis

I also cannot solve this problems until I read your post. It is so beneficial. Luv all. geometry dash scratch

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.