ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Restricting entry relationship options by category

June 15, 2010 9:21am

Subscribe [2]
  • #1 / Jun 15, 2010 9:21am

    Jaycee

    16 posts

    Does anyone know of a way to restrict the options in a relationship select field to only entries of both a specific weblog and category on that weblog?

    For example, when publishing an entry on Weblog X, I want a relationship field to only show entries of Weblog Y that are in Category Z. Is this possible out of the box or with some addon?

    I have been trying to get it working with Playa, but it appears there are no options to limit by category when output on a SAEF.

  • #2 / Jun 15, 2010 8:05pm

    lebisol

    2234 posts

    I have not seen one but I would approach the Solspace guys to make one for you - if this is SAEF specific.If you are looking to venture on your own then perhaps look into is an answer to Does SAEF allow for query module or php snip?...if yes then you can run a custom query/selection for category listing on the form.
    For what is worth…

  • #3 / Jun 16, 2010 8:44am

    Jaycee

    16 posts

    For the SAEF purposes, I found the easiest way for me is to use an embedded template on edit forms with relationship fields. The SAEF’s relationship field on an edit form would look like:

    {embed="forms/.relationship-field" id="X" selected_id="Y" category_id="Z"}

    Then the template, forms/.relationship-field, would look something like:

    <select name="field_id_{embed:id}">
    {exp:weblog:entries weblog="test" category="{embed:category_id}" orderby="title" disable="custom_fields|trackbacks|pagination"}
        <option value="{entry_id}"{if entry_id == embed:selected_id} selected="selected"{/if}>{title}</option>
    {/exp:weblog:entries}
    </select>

    So id is the number assigned to the weblog’s relationship field, selected_id is the currently selected relationship for the entry, and category_id restricts the entries shown in the relationship select field on the SAEF.

    Obviously, you could use this method for any other restriction besides category since you are using just the standard weblog:entries call to generate the relationship options field.

    Unfortunately, this method does nothing to clean up the relationship field on the EE CP Publish/Edit form. For that, the relationship field definition would need to support being able to predefine what category of a weblog’s entries should be shown.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases