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.

Limit results in related entries

May 02, 2012 12:57pm

Subscribe [1]
  • #1 / May 02, 2012 12:57pm

    nhinshaw

    13 posts

    Hello all,
    I have an issue where I have created a relationship between two channels but am having an unwanted result.

    I have a channel “products_detail” that has a relationship to a channel “shop_parent” however the “shop_parent” channel has a relationship with a channel called “products”.

    The result is that all of the channel entries in products_detail are being shown on the “shop_parent” page, mixed in with the “products” entries.

    The relationship between products detail and shop_parent exists so that I can link to a specific page in the shop section. I do not want the entry the link originated on to be visible on the shop_parent page.

    Is there a way to keep this from happening? Here is the code that is being used now:

    <a href="/shop/{related_entries">Available Online »</a>

    And here is the code on the page where the unwanted display is happening (edited for brevity)

    {exp:channel:entries channel="shop_parent" limit="1"}
    ...
    <div id="product-details">
    <section>
     <h3>{title}</h3>
    <p> {product_line_details}<br />
    </section><br />
    {exp:cartthrob:add_to_cart_form<br />
     return="cart/view_cart"<br />
     entry_id="{entry_id}"<br />
    }<br />
    <div id="select-model"><br />
     {exp:cartthrob:item_options entry_id="{entry_id}"}<br />
            <label>Choose a model</label><br />
            <select name="entry_id"><br />
             {reverse_related_entries id="product_line_parent"}<br />
              <option value="{entry_id}"><br />
                {title} {product_price}<br />
              </option><br />
             {/reverse_related_entries}<br />
            </select><br />
    {/exp:cartthrob:item_options}<br />
    ...<br />
    </div><!-- eo product details<br />
    {/exp:channel:entries}

    Specifically the issue arises in the <select> menu. I am using CartThrob, but I think this is more of a core EE issue.

    Any help or insight would be greatly appreciated. Please let me know if I can provide any more clarity.

    Thanks,
    Nathan

  • #2 / May 02, 2012 1:34pm

    nhinshaw

    13 posts

    I think I figure this out. I had missed the ability to limit by channel when invoking the reverse_related_entries tag. So I ended up with this:

    {reverse_related_entries channel="products" id="product_line_parent"}
     <option value="{entry_id}">
      {title} {product_price}
     </option>
    {/reverse_related_entries}

    Which seems to be working.

  • #3 / May 03, 2012 10:48am

    Dan Decker

    7338 posts

    Hi Nathan,

    I’m glad you found the answer!

    Keep in mind that the reverse related entries tag works differently than the related entries tag. The id= parameter is not needed, or supposed for use in {reverse_related_entries}, so you can safely remove that from your code.

    If you need anything else, just let us know in a new thread!

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases