So I’m building a job board site and I have two channels: Jobs and Applications. The Applications channel contains a relationship field that connects to the jobs channel. The idea is, when a job-seeker is viewing a job at the URL http://www.site.com/job/10, he can click an Apply button that would take him to a Safecracker form that lets him post an entry to the Applications channel with job #10 pre-populated as the related entry, since that’s the job he was viewing when he clicked the Apply button.
If the user has already applied for that job, instead of the Apply button there would be a line that reads “You have already applied for this”.
Here’s the code I’m trying:
{exp:channel:entries channel="jobs" require_entry="yes"}
{!-- If there is an entry in the Applications channel whose author is the same as the current user, tell him he applied. If not, show the Apply button: --}
{reverse_related_entries channel="applications"}
{if logged_in_member_id == '{author_id}'}
You applied for this job.
{if:else}
<a href="http://{path=job/apply/{segment_2}}">Apply for this job</a>
{/if}
{/reverse_related_entries}
{/exp:channel:entries}This apparently doesn’t work. I suspect this is because the conditional is actually saying “for all entries where the logged in member is the author, tell him he’s applied. For all other entries, show the Apply button.” So as long as anyone has applied for that job, the else statement returns true and the Apply button displays. It seems like what I need is a way to restrict the results of the reverse_related_entries to only those posted by the logged in member.
So what I need is some conditional that says “if the current user has not posted an entry to the Applications channel related to this job, then show the Apply button.”
Thoughts?