4

I have a restricted site, where users have to login to see any content. The content they are shown is restricted by their member id.

To do this, each entry is assigned to a specific member. I'm using 'VMG Chosen Member' to make this easier in the CP.

Showing the relevant entries is working fine and I'm using the following:

{exp:channel:entries channel="fsr" disable="categories|trackbacks" dynamic="off" orderby="fsr-datefield" sort="desc"}
{if logged_in_member_id == fsr-customer}
<tr>
    <td>{title}</td>
    <td>{fsr-datefield format="%Y-%m-%d"}</td>
    <td>{fsr-system-name}</td>
    <td>{fsr-call-type}</td>
    <td><a href="{fsr-pdf}" class="btn" target="_blank">Download PDF</a></td>
</tr>
{/if}
{/exp:channel:entries}

I want to apply the same limitations to search/results but when I do, it returns the correct results but if there are no results for that member but there are for other members then I get blank content and cannot redirect to the 'no results' template.

Here's my search results code:

{exp:search:search_results}
{if logged_in_member_id == fsr-customer}
<tr>
    <td>{title}</td>
    <td>{fsr-datefield format="%Y-%m-%d"}</td>
    <td>{fsr-system-name}</td>
    <td>{fsr-call-type}</td>
    <td><a href="{fsr-pdf}" class="btn" target="_blank">Download PDF</a></td>
</tr>
{/if}
{/exp:search:search_results}

I'd ideally just restrict the search or search results by member id, but that does't appear to be possible?

Does this even make any sense?!

Any other ideas? I'm really rusty with EE btw, so please be gentle :)

1
  • I'd be keen to know if you found a fix, I have a feeling low search 3 an hidden input should do the trick.
    – paulcripps
    Mar 25, 2015 at 16:42

1 Answer 1

3

Update

Since the VMG Chosen Member is a custom field that just captures the member_id and doesn't override the author_id of the entry, you could use the search parameter with Low search to find the correct entries:

{exp:low_search:form 
    collection="fsr"
    search_mode="all"
    search:fsr-customer="{logged_in_member_id}"
    result_page="search/results"
}

Make sure the fsr-customer field is set to searchable too. If this doesn't work, it's most likely a parse order issue with logged_in_member_id

Update #2

With the release of Low Search 3 just now, if the above does not work because of parse order, you can now use parameters as input fields in the latest version. So you could alternatively do this:

<input type="hidden" name="search:fsr-customer" value="{logged_in_member_id}">

I don't believe the native search module supports this type of use. You could use a 3rd party addon like Low Search which allows you to use all of the native {exp:channel:entries} parameters. So you could do something like this:

{exp:low_search:form 
    author_id="CURRENT_USER"
    collection="fsr"
    search_mode="all"
    result_page="search/results"
}
  <fieldset>
    <label for="keywords">Keywords</label>
    <input type="search" name="keywords" id="keywords" />
    <button type="submit">Search</button>
  </fieldset>
{/exp:low_search:form}

This would then return only entries of the currently logged in user. Also, I updated your relevant entries channel tag. The conditional is unnecessary when using the author_id parameter and the CURRENT_USER constant. Try this:

{exp:channel:entries channel="fsr" author_id="CURRENT_USER" disable="categories|trackbacks" dynamic="off" orderby="fsr-datefield" sort="desc"}
<tr>
    <td>{title}</td>
    <td>{fsr-datefield format="%Y-%m-%d"}</td>
    <td>{fsr-system-name}</td>
    <td>{fsr-call-type}</td>
    <td><a href="{fsr-pdf}" class="btn" target="_blank">Download PDF</a></td>
</tr>

{if no_results}
    Currently you have no entries assigned to you
{/if}
{/exp:channel:entries}
5
  • Thank you so much for the advice and apologies for the slow reply, crazy few days. I'll have a look at Low Search now, but using author_id isn't going to work for me as I'm not associating the entries to authors, as this seemed a messy way of doing in the EE CP. As mentioned, I'm using VMG Chosen Member so the content manager can assign the entry to a specific member. This means your code update doesn't work for me sadly. I'm also concerned that this will be the case if I use Low Search as well. Nov 12, 2013 at 14:39
  • Just updated my answer for you-hopefully this helps you
    – Siebird
    Nov 12, 2013 at 15:03
  • 1
    Note that when using Low Search and the search:fsr-customer="{logged_in_member_id}" parameter (apart from the parse order issues, which you could overcome by using Mo' Variables), you'll have to add it to the Results tag, not the Form tag. This applies to v3 and older versions of Low Search.
    – Low
    Nov 12, 2013 at 16:24
  • Thanks for the clarification Low! Awesome updates to v3 , can't wait to use them
    – Siebird
    Nov 12, 2013 at 16:32
  • Wow, only check Low Search a couple of hours ago and V3 wasn't there. Thanks again, I'll give it a try. Nov 12, 2013 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.