ExpressionEngine 7.5 has been Released! Learn More!
I’m trying to figure out how to display a particular entry ONLY to the logged in author of the parent entry AND to any authors of related field included in the parent entry.
This gets me 1/2 way there: {if logged_in_member_id == author_id}
What do I need to add to this conditional to pickup any authors of a related fields?
Not entirely clear from your question what you are trying to do: what are “authors of related field” … ?
It also is not clear whether these target entries come from any channel, a sub-set of channels, or the same channel that the entry you are getting the author details from.
In general, the solution to the question is probably the same regardless of how these questions might be answered, but the specifics of how you go about implementing it will vary significantly depending on any specifics that might come from thinking about such answers.
So in general, you probably cannot come up with a conditional that can be applied to just one channel entry listing to solve this. What you need to do is approach this via multiple steps. Broadly something like:
Work out what channels might contain the information you are looking for and list the contents of these - saving the author field_id and either the entry_id or the url_title of the records they contain, along with whatever the “related field” value is that you want eventually to pair up with the entry concerned to a set of layout variable arrays (i.e. one layout variable array for each factor). If you need to run multiple channel entries calls to get this information you can simply run multiple channel entry loops in series and append the results - to end up with a set of arrays that collectively contain all the records that might be relevant to your query.
Next you need to identify the “related field” value is for entry whose visibility you want to control. To do this, run a layout variable replay loop using the arrays you built in the first step. Run through your layout variable array (this, due to the limitations of layout variables will need to be happening on the “next” template in your template layout stack) and use a conditional to save from this list the author_id’s for each value in your array set that has the appropriate “related field” value. This intermediate layout variable array will contain the author_id’s of all the people who can be allowed to ‘see’ the entry concerned.
Next you need to turn your intermediate layout variable array into a pipe separated list of values. You can do this by (on yet another template in your stack) replaying the intermediate layout array and building up your pipe separated list in a regular layout variable (if you are good at this sort of thing, you possibly could create this pipe separated list as the output from the previous step and miss this step out).
Finally you need to use this pipe separated list in your conditional determining whether or not the visitor can ‘see’ the entry or not. You can do this using the “contains” conditional operator to compare your visitors logged_in_member_id
with the values in your pipe separated list - if the value is found, show them the content, if it is not, don’t.
The above is not hugely efficient: if you have the skills doing the above in an add-on would be better - but it should do the job.
HTH
🐾
@five nights at freddy’s, To display an entry to the logged-in member and any authors of related fields, you can combine the logged_in_member_id and author_id conditions with a check for related field authors. Here’s how you can do it:
{if logged_in_member_id == author_id OR logged_in_member_id IN {related_field_authors}} {/if} Replace related_field_authors with the actual field handle of your related field. This will evaluate to a list of author IDs associated with the related field entries.
Here’s a breakdown of how this works:
logged_in_member_id == author_id: This checks if the logged-in member is the author of the parent entry. logged_in_member_id IN {related_field_authors}: This checks if the logged-in member is among the authors of any related field entries. By combining these conditions with the OR operator, you ensure that the content is displayed to both the author of the parent entry and any authors of related fields.
Example:
If your related field is called related_authors, you would use:
{if logged_in_member_id == author_id OR logged_in_member_id IN {related_authors}} {/if} Remember to replace related_authors with the actual field handle of your related field.
@spendmoney, to achieve the desired functionality, you need to expand the conditional to include a check for authors in the related fields. In addition to checking if the logged-in member is the author of the parent entry, you should add logic that verifies if the logged-in user is one of the authors in the related fields. This could involve fetching the IDs of authors from the related fields and comparing them to the logged-in member’s ID.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.