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.

Related entries from same channel

August 21, 2012 4:43pm

Subscribe [2]
  • #1 / Aug 21, 2012 4:43pm

    Eric_WVGG

    10 posts

    I have a pair of channels, Blog_posts and Profiles. Blog_posts.profiles is a multi-relationship field to Profiles, thus making a many:many relationship between the tables. In other words, a blog post might reference multiple profiles, and a profile will be included in many blog posts.

    I need to query “all blog posts from all referenced profiles” from a blog post. i.e. if a Post links to the Andy and Bill profiles, I need a list of all posts that link to the Andy and Bill profiles.

    I thought I could do…

    {exp:channel:entries channel="blog_posts" limit="16" dynamic="no" search:profiles="{profiles}"}

    …but it’s not working. I only noticed the fine print in the documentation — ‘Only fields of the type “Text Input”, “Textarea”, and “Drop-down Lists” are searched with this parameter’ — a moment ago.

    Any thoughts? I thought I could bust out a MySQL query, but the profiles column in the database doesn’t even appear to reference exp_channel_data rows.

  • #2 / Aug 22, 2012 1:44pm

    Eric_WVGG

    10 posts

    *bump* for the noon crowd

  • #3 / Aug 22, 2012 2:18pm

    Rob Allen

    3114 posts

    How are you relating Profiles to Posts? Are you using the generic related entries field type or Playa?

  • #4 / Aug 22, 2012 2:26pm

    Eric_WVGG

    10 posts

    Generic.

    (to clarify, the Posts channel has a Multi-Relationship channel field called “Profiles”, which relates to the Profiles channel)

  • #5 / Aug 22, 2012 4:35pm

    Dan Decker

    7338 posts

    Hi Eric,

    Generic.

    (to clarify, the Posts channel has a Multi-Relationship channel field called “Profiles”, which relates to the Profiles channel)

    Those are contradictory statements. ExpressionEngine generic, native relationship field type is a one-to-one. Any field that allows for many-to-may is 3rd party.

    Are you using this field type? Any full template code you can share?

    Thanks!

  • #6 / Aug 22, 2012 4:36pm

    Eric_WVGG

    10 posts

    My apologies, you are correct, I’m using that add-on.

  • #7 / Aug 23, 2012 1:36pm

    Dan Decker

    7338 posts

    Hey Eric,

    I really do want to help:

    Any full template code you can share?

    If you can show me how you are piecing this all together, I can hopefully give you the answers you need. Without some code though, it’s like flying blind.

    Cheers,

  • #8 / Aug 23, 2012 1:48pm

    Eric_WVGG

    10 posts

    Sorry, didn’t think non-functional code would help, and I’ve tried dozens of variants.

    Regarding the data structure, there’s a Blog channel, and a Profiles Channel. One of the Blog channel fields is Profiles, a Multi-Relationships field. Under its Field Options / “Select the channel you wish to create a relationship with:”, the Profiles channel is selected.

    Here’s one variant I’ve tried…

    {exp:channel:entries channel="blog" }
    {embed="shared/related_article" profiles="{profiles}"}
    {/exp:channel:entries}

    …and then in an embedded template:

    {exp:channel:entries channel="blog" limit="16" dynamic="no" search:profiles="{embed:profiles}"} 
      {title} etc.
    {/exp:channel:entries}

    Assuming this doesn’t work because “exp:channel:entries search:” cannot access Multi-Relationships.

    I’m getting the impression that Playa would handle this kind of thing better, I’m ready to make the investment if I have to.

  • #9 / Aug 24, 2012 3:40pm

    Dan Decker

    7338 posts

    Hey Eric,

    You’re working too hard man! Let the add-on do its thang!

    Ok, looking at the add-on page, it can either work with native {related_entries} tags or return a delimited list of entry IDs.

    Uses native tags {related_entries} and {reverse_related_entries}.
    {mrelshp:ids field=“my_field”} returns pipe list of related entries IDs.

    Method one: - {related_entries}

    {exp:channel:entries channel="blog" }
     {related_entries id="profiles"}
      {title}
    
     {/related_entries}
    {/exp:channel:entries}

    That should pull all titles from the profiles channel that have been related to the blog channel’s entry

    Method 2 - {mrelshp:ids field=“my_field”} tag

    {exp:channel:entries channel="blog" }
     {embed='/shared/related_article' my_profiles='{mrelshp:ids field=“profiles”}'
    {/exp:channel:entries}
    
    then…
    {exp:channel:entries channel="profiles" limit="16" dynamic="no" fixed_order="{embed:my_profiles}""} 
      {title} etc.
    {/exp:channel:entries}

    I suggest method 1 for performance reasons, but either should work just fine.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases