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.

Using Playa and Custom Query Module

September 28, 2009 1:04pm

Subscribe [2]
  • #1 / Sep 28, 2009 1:04pm

    Hi all, I’ve used Playa to create several relationships (and quite easily) between a client’s entries regarding their attorneys and their multiple practice areas. The Playa functionality works without any hiccups and displays those practice areas perfectly.

    However, I’m running into an issue with the reverse_related_entries on the Practice Areas page as the client wants those divvied up between the various Attorney rankings (Partner, Associate, etc.). The only way I can return this info is by using this code:

    <h3 class="tg">Partners</h3>
    <ul>
    {exp:weblog:entries weblog="practice_areas|specialties"}
    {reverse_related_entries}
    {if job_title == "Partner"}
            <li><a href="http://{site_url}index.php/attorneys/detail/{url_title}">{title}</a></li>
    {/if}
    {/reverse_related_entries}
    {/exp:weblog:entries}
    </ul>

    Clearly, the problem with that method is that if there isn’t anything matching “Partner” (in this example), then it will display a header with no data below it. This isn’t acceptable for the client, so I’m looking into using the Custom Query Module.

    However, I’m in the dark on how to search for a relationship’s values and return info matching it. It’d be one thing if I could easily parse and find out the relationship, but I’m afraid I’m in the dark on how to find this information. Do I have to join the weblog titles, weblog data and the weblog relationships together in this query? If so, what would I need to do?

    I’m sorry if I’m asking anything incorrectly. I’m just very new to the custom query module, and don’t know where to start in this instance!  😖

  • #2 / Sep 28, 2009 2:03pm

    AnotherMuse

    106 posts

    I think the count variable may be available in reverse_related_entries.

    Have you tried this:

    {exp:weblog:entries weblog="practice_areas|specialties"}
    {reverse_related_entries}
    {if count == 1}<h3 class="tg">Partners</h3>
    <ul>{/if}
    {if job_title == "Partner"}
            <li><a href="http://{site_url}index.php/attorneys/detail/{url_title}">{title}</a></li>
    {/if}
    {if count == total_results}</ul}{/if}
    {/reverse_related_entries}
    {/exp:weblog:entries}

    Edit: you may need to play around with the conditionals to get the right heading with each job title, but this would still probably be easier than a custom query.

  • #3 / Sep 28, 2009 2:09pm

    Unfortunately, AnotherMuse, that ends up not working because what that says is “if there’s any in this field” and then says “if the job title matches Partner”, so if I have anyone that matches that field, but isn’t partner, then the same problem shows up. :(

  • #4 / Sep 28, 2009 2:20pm

    ender

    1644 posts

    could use some php to make it work properly… it’s not elegant but it ought to work.

    <?php $partners = ""; ?>
    {exp:weblog:entries ...}
        {reverse_related_entries}
            <?php $partners .= "<li>...</li>"; ?>
        {/reverse_related_entries}
    {/exp:weblog:entries}
    
    <?php
        if($partners != "") {
            print "<h3>Partners</h3><p>" . $partners;<br />
        }<br />
    ?>

    php set to output processing of course.

  • #5 / Sep 30, 2009 9:48am

    Hi ender, thanks for the suggestion. I’m not sure I really understand this, though. I am unfortunately pretty green to PHP, and don’t know what I should look to change/edit/etc.

    Mind explaining it a little?

    Sorry to be dense 😊

  • #6 / Sep 30, 2009 11:59am

    ender

    1644 posts

    basically instead of printing the list items out directly to the browser, you send all that text to a php variable… then after the weblog:entries tag is done you check to see if there’s anything in the php variable before printing the header followed by the contents of the variable.

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

ExpressionEngine News!

#eecms, #events, #releases