Support » Plugin: Pods - Custom Content Types and Fields » List titles from pods in relationship

  • Resolved Luuk Fiets

    (@luukfiets)


    Hi,

    I’m a bit lost. I’ve set up two pods: the first one is for agencies, the second one is for services they’re offering. I’ve connected these by setting up a bidirectional relationship field. On the agencies pod this field is called “related_services” and on the other one it’s called “related_agencies”.

    What I’m trying to achieve is to list all agencies that are offering the service that the visitors is currently looking at. So for example someone is looking at service A, then I’d like to list all agencies that are offering service A. I would like to do it the other way as well: list all services that agency A is offering, when someone is looking at the agency page of agency A.

    I’ve tried multiple variations. Let’s think of the situation where someone is looking at service A and we want to list all agencies offering service A. I’ve tried the following shortcode:

    [pods name="agencies" limit="3" where="related_services.meta_value = 'service A' "]
    {@post_title}
    [/pods]

    I tried where="agencies.related_services.meta_value='service A'" and other things as well, but for some reason I don’t get it to work. Unfortunately, the documentation doesn’t really help me to understand what I have to change. Do you have any ideas?

    Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @luukfiets
    Please try where="t.related_services.meta_value = 'service A' "
    Cheers, Jory

    Hi @keraweb

    Thanks for sharing. I changed the shortcode, but it gives me an error. The full shortcode I was using is below. Background information: Agency 1 is connected to Service A, so I’d like “Agency 1” to appear.
    [pods name="agency" where="t.related_services.meta_value = 'Service A' "]{@post_title}[/pods]

    The error I got was this one. I tried Google but didn’t find anything really useful. Someone suggested to use this_related_field.other_related_field.meta_value = ‘text here’ but that didn’t work either.
    Database Error; SQL: SELECT DISTINCTt.* FROMwp_postsAStWHERE ( ( t.related_services.meta_value = 'Service A' ) AND (t.post_type= "agency" ) AND (t.post_statusIN ( "publish" ) ) ) ORDER BYt.menu_order,t.post_title,t.post_dateLIMIT 0, 15; Response: Unknown column 't.related_services.meta_value' in 'where clause'

    Do you maybe have a suggestion for what I should try next or where I can find more (relevant) information?

    Thanks!

    • This reply was modified 1 month, 2 weeks ago by Luuk Fiets.
    • This reply was modified 1 month, 2 weeks ago by Luuk Fiets.
    Plugin Author Jory Hogeveen

    (@keraweb)

    Upon re-reading this, keep in mind that relationships are post ID’s. So disregard my first comment, that wasn’t your issue. The issue was that Service A isn’t a post ID.

    I’d change the way you are fetching the related agencies. Since these are bi-directional fields you could just use [pods field="related_agencies_field"] if you use it in the post content.
    Let me know if this helps!

    Cheers, Jory

    Hi Jory,

    Thanks for getting back. After posting I read somewhere that indeed it saves the post ID instead of the text. I tried testing a few solutions, but didn’t get it to work with inserting an ID.

    However, your second solution did make sense. It lists the agencies like “Agency 1, Agency 2 and Agency 3”. Good to know that this is one way, but what I’d like to achieve is an unordered list with clickable agencies.

    So, my next step was to try the templates. I’ve set up a template with te following code in it:

    [each related_agencies]
    <a href="{@permalink,esc_url}"><p>{@post_title}</p></a>
    [/each]

    In the post of service A I’m calling the template with the following shortcode:
    [pods template="List all related agencies"]. This works as expected and gives back an unordered list with all related agencies including the a href tag. However, I would like to limit the number of results I’m getting back. Lets say I want a max of 3 agencies being listed. Unfortunately, adding limit="3" to the shortcode doesn’t work.

    If you can help me with figuring out how to get the related agencies when using post ID (instead of “Service A”), then I might be able to use that shortcode and try to limit that one, because that seems possible looking at the documentation.

    I think I’m getting there with something like this (32 = Service A):
    [pods name="services" limit="3" where="related_agencies.related_services.meta_value = '32'"][each related_service]{@permalink} is great![/each][/pods]

    Do you have any suggestions to limit the results to any number?

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @luukfiets

    Looking at your case I think this might work:
    [pods name="agencies" limit="3" where="related_services.meta_value IN ('32')"]{@permalink} is great![/pods]

    So, you are fetching agencies limited by 3 where the related_services field contains a value of 32. The inner content should not need an each loop.
    * Keep in mind that this cannot be used inside a Pods template since {@permalink} would echo the permalink of the current post, not the post in the loop. If you want your own views/loops in a Pods Template then these should be separate templates.

    In any case I’d have to take a better look tomorrow to be sure. I personally prefer PHP templates for flexibility.

    Let me know if this helps!

    Cheers, Jory

    PS: Leuk om te zien dat steeds meer mensen uit NL Pods gaan gebruiken!

    Plugin Author Jory Hogeveen

    (@keraweb)

    Closing due to no response. Feel free to re-open if needed!

    Cheers, Jory

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.