Title: Relationship field in shortcode
Last modified: March 25, 2024

---

# Relationship field in shortcode

 *  Resolved [reedenj](https://wordpress.org/support/users/reedenj/)
 * (@reedenj)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/relationship-field-in-shortcode/)
 * 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](https://wordpress.org/support/users/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](https://wordpress.org/support/users/sc0ttkclark/)
 * (@sc0ttkclark)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/relationship-field-in-shortcode/#post-17527655)
 * 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/](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](https://wordpress.org/support/users/reedenj/)
 * (@reedenj)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/relationship-field-in-shortcode/#post-17530125)
 * 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](https://wordpress.org/support/users/sc0ttkclark/)
 * (@sc0ttkclark)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/relationship-field-in-shortcode/#post-17530200)
 * 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](https://wordpress.org/support/users/reedenj/)
 * (@reedenj)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/relationship-field-in-shortcode/#post-17530355)
 * Here’s the output for the shortcode
 *     ```wp-block-code
                   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](https://wordpress.org/support/users/reedenj/)
 * (@reedenj)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/relationship-field-in-shortcode/#post-17530504)
 * 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](https://wordpress.org/support/users/reedenj/)
 * (@reedenj)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/relationship-field-in-shortcode/#post-17533435)
 * 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.

 * ![](https://ps.w.org/pods/assets/icon.svg?rev=3286397)
 * [Pods - Custom Content Types and Fields](https://wordpress.org/plugins/pods/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/pods/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/pods/)
 * [Active Topics](https://wordpress.org/support/plugin/pods/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/pods/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/pods/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [reedenj](https://wordpress.org/support/users/reedenj/)
 * Last activity: [2 years, 2 months ago](https://wordpress.org/support/topic/relationship-field-in-shortcode/#post-17533435)
 * Status: resolved