Version: EE4.0.9
Hi everyone!
I am trying to get all of the entries through my module and I noticed that when querying on the ChannelEntry Model, when accessing custom fields, the only way to get them is from the field_id and not their shortname.
Example:
public function get_entries()
{
$entries = ee('Model')->get('ChannelEntry')->filter('channel_id', 1)->all();
foreach($entries as $entry) {
var_dump($entry->field_id_1);
}
}
Is there a way to efficiently access the properties by their shortname/handle with something like
entry->my_custom_field_name
Like this, im try this and Works Fine(on my own Custom Addon)
Pass Custom Field name, and Return Custom Field ID
private function getfieldID($ci){
$field = ee('Model')->get('ChannelField')
->filter('field_name', $ci) // or whatever you want/need to filter on
->first();
return $field->field_id;
}
In this function im filter Channel Entry by Channel ID and custom Field Value(member_id)
function add_product(){
$this->member_id=ee()->session->userdata('member_id');
$field_id=$this->getfieldID("cliente_id");
$entries = ee('Model')->get('ChannelEntry')
->filter('channel_id', $this->channel_id) // or whatever you want/need to filter on
->filter('status', 'IN', array('open', 'other_status'))
->filter('field_id_'.$field_id, $this->member_id)
->order('title', 'ASC')
->all();
foreach($entries->toArray() as $trow){
print_r($trow);
}
$this->return_data="algo ss";
return $this->channel_id;
}
}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.