Okay
  Public Ticket #3110290
SQL Query Conditions
Closed

Comments

  • Frank Paladino started the conversation

    Greetings,

    I have custom post types created by the Pods plugin. The custom post types have custom meta data. In the screenshot below, you can see that I have a post type "Lot", and I want to show a table of lots where the "Lot Status" is "Scheduled", represented by the numeric value 1199.

    2452647077.png

    However, when I try to move to the next step, the query does not return any results.

    7371416381.png

    You can see that the lot.meta option of lot status appears, and you can see from the next screenshot that other meta tags I have on the custom post appear as well.

    6683060253.png

    Unfortunately, I cannot generate any results with any of the meta tags used as a condition. I tried all meta tags, and tried both the value ("1199" in my first example) and the string ("Scheduled" in my first example). When no conditions are attached, the table populates normally.

    It seems like, although the meta options appear as possible condition options, the SQL query isn't making the connection?

    Can you please help me resolve this issue? If you need any more information, please let me know.

    Thank you!

  • Frank Paladino replied

    So I figured this out. Turns out that the syntax for targeting a meta value on a post created via Pods was the issue. After some feedback from Pods, I managed to get it working using the following query:

    SELECT posts_lot.post_title AS lot_post_title,
           lot_meta_product_tbl.meta_value AS lot_meta_product,
           lot_meta_quantity_tbl.meta_value AS lot_meta_quantity,
           lot_meta_lot_status_tbl.meta_value AS lot_meta_lot_status,
           lot_meta_room_tbl.meta_value AS lot_meta_room
    FROM fzMCGsSFposts AS posts_lot
      INNER JOIN (SELECT lot_meta_product_tbl_posts.ID as id, meta_value, meta_key  FROM fzMCGsSFpostmeta AS lot_meta_product_tbl_postmeta  INNER JOIN fzMCGsSFposts AS lot_meta_product_tbl_posts   ON lot_meta_product_tbl_postmeta.post_id = lot_meta_product_tbl_posts.ID   AND lot_meta_product_tbl_posts.post_type = 'lot') AS lot_meta_product_tbl
         ON lot_meta_product_tbl.meta_key = 'product' AND lot_meta_product_tbl.id = posts_lot.ID 
       INNER JOIN (SELECT lot_meta_quantity_tbl_posts.ID as id, meta_value, meta_key  FROM fzMCGsSFpostmeta AS lot_meta_quantity_tbl_postmeta  INNER JOIN fzMCGsSFposts AS lot_meta_quantity_tbl_posts   ON lot_meta_quantity_tbl_postmeta.post_id = lot_meta_quantity_tbl_posts.ID   AND lot_meta_quantity_tbl_posts.post_type = 'lot') AS lot_meta_quantity_tbl
         ON lot_meta_quantity_tbl.meta_key = 'quantity' AND lot_meta_quantity_tbl.id = posts_lot.ID
      INNER JOIN (SELECT lot_meta_lot_status_tbl_posts.ID as id, meta_value, meta_key  FROM fzMCGsSFpostmeta AS lot_meta_lot_status_tbl_postmeta  INNER JOIN fzMCGsSFposts AS lot_meta_lot_status_tbl_posts   ON lot_meta_lot_status_tbl_postmeta.post_id = lot_meta_lot_status_tbl_posts.ID   AND lot_meta_lot_status_tbl_posts.post_type = 'lot') AS lot_meta_lot_status_tbl
         ON lot_meta_lot_status_tbl.meta_key = 'lot_status' AND lot_meta_lot_status_tbl.id = posts_lot.ID 
      INNER JOIN (SELECT lot_meta_room_tbl_posts.ID as id, meta_value, meta_key  FROM fzMCGsSFpostmeta AS lot_meta_room_tbl_postmeta  INNER JOIN fzMCGsSFposts AS lot_meta_room_tbl_posts   ON lot_meta_room_tbl_postmeta.post_id = lot_meta_room_tbl_posts.ID   AND lot_meta_room_tbl_posts.post_type = 'lot') AS lot_meta_room_tbl
         ON lot_meta_room_tbl.meta_key = 'room' AND lot_meta_room_tbl.id = posts_lot.ID 
    WHERE 1=1 
       AND posts_lot.post_type = 'lot'

    I wanted to share this with your team, in case there is anything you can glean from it, as well as for anyone else using the Pods plugin to create custom post types and meta data.

    Just to clarify for anyone using pods:

    Pods: Lot, Lot Status, Room, Product

    On the 'Lot' pod, there are several fields: Lot Status, Room, Product, and Quantity (not itself a pod, but just an open field for a number).

    Hope this helps!

  •  2,572
    Aleksandar replied

    Hey Frank

    Thank you very much for sharing this with us.

    I'll forward the ticket to our developers in case they can work something out with your information. I'm sure other users that use Pods will be grateful for this.

    Please feel free to reach out to us if you have any further questions.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables