• Resolved reedenj

    (@reedenj)


    Hello,

    I’m struggling with the following:

    I have a pod called “cars” with entries such as Ford, Mondeo, Escort etc, and I’d like to make a list of cars on each manufacturer page (still the same pod called cars).

    I created a relationship field “brand” with related type “cars”, where I can pick what I need, and I tried to use the shortcode to create a list, but no dice.

    [pods name="cars" where=" brand.meta_value = '@ID'" template="XX"]

    I tried to use .slug, @post_title, @guid etc, various combinations, but nothing. How I can compare a value from a relationship field with current post, eg ID or post_title within the same pod (cars)?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    This may work for you:

    [pods name="cars" where="brand.meta_value = '{@post_id}'" template="XX"]

    See here for more details: https://docs.pods.io/displaying-pods/magic-tags/special-magic-tags/

    Read the important note on that doc page about needing the constant, that’s probably what you’ll need as well since you’re using this in the shortcode.

    Thread Starter reedenj

    (@reedenj)

    Thanks for the reply. Unfortunately, it doesn’t seem to work. I added the necessary constant to wp-config, and used the shortcode with {@post_id}

    I tried with and without ”, but neither option works.

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    As an admin, try adding ?pods_debug_sql=1 to the URL of the page you’re testing on. This should output the full query that Pods ends up using. This may give us some further clues as to what’s going on here.

    Thread Starter reedenj

    (@reedenj)

    Here’s the output for the shortcode

                SELECT
    
                DISTINCT
                t.*
                FROM wp_posts AS t
    
                        LEFT JOIN wp_podsrel AS rel_brand ON
                            rel_brand.field_id = 29331
                            AND rel_brand.item_id = t.ID
    
                        LEFT JOIN wp_posts AS brand ON
                            brand.ID = rel_brand.related_item_id
    
    
                    LEFT JOIN wp_postmeta AS brand_meta_value ON
                        brand_meta_value.meta_key = 'meta_value'
                        AND brand_meta_value.post_id = brand.ID
    
                WHERE ( (  brand.meta_value = ''  ) AND ( t.post_type = 'cars' ) AND ( t.post_status IN ( 'publish' ) ) )
    
    
                ORDER BY t.menu_order, t.post_title, t.post_date
                LIMIT 0, 100
    Thread Starter reedenj

    (@reedenj)

    As you can see in the log, {@post_id} outputs an empty value for me, not sure why. I tried to use {@ID}, which outputs the correct post ID (not sure if that’s valid magic tag?). Anyway, my shortcode still doesn’t work, so I wonder, what is the meta_value of relationship field? Is it the page’s ID?

    Thread Starter reedenj

    (@reedenj)

    I managed to make it work (at least it seems so). I used .id instead .meta_value, with the necessary constant added to wp-config.

    [pods name="cars" where=" brand.id = '{@ID}'" template="XX"]

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Relationship field in shortcode’ is closed to new replies.