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

Returning entries based on user in a CKI Member List custom field

Development and Programming

PressEnter Creative's avatar
PressEnter Creative
235 posts
15 years ago
PressEnter Creative's avatar PressEnter Creative
{exp:channel:entries channel="channel" dynamic="no" limit="10000" orderby="title" sort="asc" disable="categories|member_data|pagination"}    
    {if logged_in_username == "{entry_user_1 get="username"}"  || logged_in_username == "{entry_user_2 get="username"}" || logged_in_username == "{entry_director_user_3 get="username"}"}
        {title}, etc...
    {/if}
{/exp:channel:entries}

The code above will display all entries from a channel where the user logged into EE is one of the users specified in one of the entry’s CKI Member List custom fields.

This code segment executes very slowly, I’d imagine because it’s looping through every entry in the channel and then comparing three custom fields for each of them; is there any sort of way to apply the search=”” parameter to these custom fields in the entry loop? Since it’s not a “Text Input”, “Textarea”, or “Drop-down List” I’m not sure what the next step should be.

       
the3mus1can's avatar
the3mus1can
426 posts
15 years ago
the3mus1can's avatar the3mus1can

After briefly scanning the code for the CKI member list field type, the data being saved in the db is just the member_id. You could use PHP (input) in the template and pass a set of entry ids into the entries tag. Very basic example below:

field_id_x = the column name for those CKI custom field in the database.

<?php 
    $EE = get_instance();
    
    $member_id = $EE->session->userdata('member_id');
    
    $query = $EE->db->query("SELECT DISTINCT(entry_id) FROM exp_channel_data WHERE (field_id_x = $member_id OR field_id_x = $member_id OR field_id_x = $member_id)");

    $entry_ids = array();
            
    if ($query->num_rows > 0) 
    {
        foreach ($query->result_array() as $row) 
        {
            $entry_ids[] = $row['entry_id'];
        }
    }
    
    $entry_ids = implode('|', $entry_ids);
    
?>

{exp:channel:entries channel="channel" entry_id="<?php echo $entry_ids; ?>" dynamic="no" limit="10000" orderby="title" sort="asc" disable="categories|member_data|pagination"}    
        {title}, etc...
{/exp:channel:entries}
       
PressEnter Creative's avatar
PressEnter Creative
235 posts
15 years ago
PressEnter Creative's avatar PressEnter Creative

I’ll investigate this tomorrow; thank you so much for taking the time to respond!

       

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.