Title: Hack wordpress and Pods
Last modified: February 2, 2024

---

# Hack wordpress and Pods

 *  Resolved [samuelvincent](https://wordpress.org/support/users/samuelvincent/)
 * (@samuelvincent)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/hack-pods/)
 * hi!
 * I am a developer who has been discovering wordpress for some time now but I am
   not an engineer so I try to manage as I can as I learn and discover wordpress.
   So I tinker as much as I can to achieve my goals
 * My problem is quite simple.
 * I have to develop a slightly special sponsorship system because I have to respect
   certain constraints…
 * One person can sponsor another and both benefit from a 50€ discount. only his
   50€ are cumulative for the sponsor and are unlocked when the godchild has booked
   and exceeded the legal cancellation and withdrawal periods.
 * I use the event manager eventmanagement plugin that I have already adapted a 
   lot to my needs. this plugin has a very simple discount coupon system that I 
   use to make people benefit from its 50th discount. only you can’t use several
   discount coupons when booking…
 * If I want to allow the sponsor to accumulate on a single discount voucher several
   referral referrals, and benefit from a greater discount when booking a training
   course, I am obliged to develop a separate system.
 * So that the sponsor can send his discount voucher to a godchild, I use a formidablesforms
   form.
 * This allows you to save the entries of this form while also saving them in a 
   CPT. This allows me to record other data for each entry of the form.
 * When validating this form, I wrote a script in php that creates a record in the
   discount coupon table of the eventsmanager plugin.
 * After the legal cancellation and withdrawal periods, I run a script in php that
   looks for the discount coupons used by godchildren, and I look for whether a 
   discount coupon already exists for the godchild’s godfather.
   If this is the case
   and if it has not already been used, I add this amount to the amount of the discount
   coupon found.Otherwise, in any case, I create a new one.
 * This is where I need to create another CPT that allows me to store the coupons
   generated by this script with other information to allow me to link the discount
   coupon assigned to the sponsor, to the discount coupons that he sent to his godchildren…
   this in order to keep a history of operations!
 * I can do all this very well except that when I want to save a value for the link
   menu popup with the first CPT, it does not appear as an element selected in the
   popup menu…
   No matter how much I search the wordpress database, I can’t find 
   what would make this link appear well in the ppopup menu.
 * I noticed that the item selected in the popup field was saved in the postmeta
   table with as meta_value, a serialization with the ID of the CPT record (for 
   example {i:0;i:1049;} ).
 * I also noticed that the link between the fields of the two CPTs was recorded 
   in the podsrel table.
 * All this does not change the fact that when I open one of the records of the 
   second cpt, the link field does not automatically select the corresponding record
   of the first…
 * Is there anything more mysterious I would have to do to make it work?
    -  This topic was modified 2 years, 4 months ago by [samuelvincent](https://wordpress.org/support/users/samuelvincent/).

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

 *  Thread Starter [samuelvincent](https://wordpress.org/support/users/samuelvincent/)
 * (@samuelvincent)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/hack-pods/#post-17393126)
 * Here are my actions in the database:
 * 1 – Search for referral coupons to be processed:
 * SELECT `getPhpSerializedArrayValueByKey`(mod185_em_bookings.booking_meta, ‘coupon_code’)
   AS coupon_code, mod185_em_bookings.booking_status, mod185_em_bookings.person_id,
   mod185_em_bookings.booking_id, mod185_em_events.event_id, mod185_em_events.event_start_date,
   DATEDIFF(mod185_em_events.event_start_date, CURDATE()) AS nbr_jours_avant_formation
   FROM mod185_em_bookings INNER JOIN mod185_em_coupons ON `getPhpSerializedArrayValueByKey`(
   mod185_em_bookings.booking_meta, ‘coupon_code’) = mod185_em_coupons.coupon_code
   INNER JOIN mod185_em_events ON mod185_em_bookings.event_id = mod185_em_events.
   event_id WHERE `getPhpSerializedArrayValueByKey`(mod185_em_bookings.booking_meta,‘
   coupon_code’) IS NOT NULL AND DATEDIFF(mod185_em_events.event_start_date, CURDATE())
   <= 30
 * sponsor : coupon_code_parrain = 588-PARRAIN50-447
   godchildren : coupon_code_filleul
   = 447-FILLEUL50-588
 * 2: Search if the coupon already exists:
 * SELECT mod185_em_coupons.coupon_code FROM mod185_em_coupons WHERE mod185_em_coupons.
   coupon_code LIKE ‘447-FILLEUL50-588’
 * 3 – Creates the coupon in the reservation system:
 * INSERT INTO mod185_em_coupons ( coupon_owner, blog_id, coupon_code, coupon_name,
   coupon_description, coupon_max, coupon_start, coupon_end, coupon_type, coupon_tax,
   coupon_discount, coupon_eventwide, coupon_sitewide, coupon_private ) VALUES (
   2, NULL, ‘447-FILLEUL50-588’, ‘PARRAINAGE 50€’, ’50€ de remise à un parrain –
   Tarif normal’, 1, ‘2024-02-02’, ‘2025-02-02’, ‘#’, ‘pre’, 50.00, 0, 1, 0 )
 * insertSQL_emcoupons_id = 15
 * 4 – Create the coupon in pods 1/2 (posts):
 * INSERT INTO mod185_posts ( post_author, post_date, post_date_gmt, post_content,
   post_title, post_excerpt, post_status, comment_status, ping_status, post_password,
   post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered,
   post_parent, menu_order, post_type, post_mime_type, comment_count ) VALUES ( 
   2, ‘2024-02-02’, ‘2024-02-02’, ”, ‘447-FILLEUL50-588’, ”, ‘publish’, ‘closed’,‘
   closed’, ”, ‘447-FILLEUL50-588’, ”, ”, ‘2024-02-02’, ‘2024-02-02’, ”, 0, 0, ‘
   parrainages_filleuls’, ”, 0 )
 * insertSQL_posts_id = 9860
 * 5 – Update the coupon in pods 1/2 (posts):
 * UPDATE mod185_posts SET mod185_posts.guid = ‘[https://dev.lesformations.ygyforyou.com/?post_type=parrainages_filleuls&p=9860&#8217](https://dev.lesformations.ygyforyou.com/?post_type=parrainages_filleuls&p=9860&#8217);
   WHERE mod185_posts.ID = 9860
 * 6 – Search for the sponsor coupon in the pod (posts):
 * SELECT mod185_posts.ID FROM mod185_posts WHERE mod185_posts.post_title LIKE ‘
   588-PARRAIN50-447’
 * 7 – Create the coupon in pods 2/2 (postmeta):
 * INSERT INTO mod185_postmeta ( post_id, meta_key, meta_value ) VALUES ( 9860, ‘
   parrainage_filleul_id’, ‘755’ ), ( 9860, ‘_pods_parrainage_parrain’, ‘a:1:{i:
   0;i:9407;}’ ), ( 9860, ‘parrainage_parrain’, ‘9407’ )
 * 8 – Creates the link (podsrel):
 * INSERT INTO mod185_podsrel ( pod_id, field_id, item_id, related_pod_id, related_field_id,
   related_item_id, weight ) VALUES ( 9851, 9858, 9859, 0, 0, 9407, 0 )
    -  This reply was modified 2 years, 4 months ago by [samuelvincent](https://wordpress.org/support/users/samuelvincent/).
    -  This reply was modified 2 years, 4 months ago by [samuelvincent](https://wordpress.org/support/users/samuelvincent/).
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/hack-pods/#post-17393831)
 * A PHP serialized array is a data format which is not accessible to most applications
   via MySQL.
 * The necessary action is to save the relationship as one ID per row to a Pods 
   meta field using add_post_meta or [https://docs.pods.io/code/pods/save/](https://docs.pods.io/code/pods/save/)
 *  Thread Starter [samuelvincent](https://wordpress.org/support/users/samuelvincent/)
 * (@samuelvincent)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/hack-pods/#post-17393884)
 * Oh thank you!
 * As for serialized content, it is really not complicated… “a:1:{i:0;i:9407;}” 
   or 9407 is the ID of the main pods.
 * When I do it from the pods form it works very well and it puts it as a value.
   so I don’t see why it doesn’t work by sql.
 * But I will immediately look at your link and test.
 * Thanks !!!!
    -  This reply was modified 2 years, 4 months ago by [samuelvincent](https://wordpress.org/support/users/samuelvincent/).
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/hack-pods/#post-17461341)
 * Okay, great, hope that pointed you in the right direction.
 * Yes, I realize that the serialized data format is not complicated — what I meant
   was that the effect of another plugin choosing that format is that the field 
   is not trivially queryable with MySQL.
 * Reading your request again, it sounds like there is a desire for bookkeeping,
   e.g., what code was used by whom through what relationship.
 * Such configurations get very specific and complex depending on what pre-existing
   software one wants to leverage or integrate with. But generally, in a Pods context,
   you might find benefit from creating an additional private post type, for example`
   ledger`, which uses the coupon code as the title/slug, has a field for amount/
   value, relationship fields to the code’s user and provider user accounts, using
   the publish date as the time at which the code was used.

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

The topic ‘Hack wordpress and Pods’ 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/)

 * 4 replies
 * 2 participants
 * Last reply from: [pdclark](https://wordpress.org/support/users/pdclark/)
 * Last activity: [2 years, 3 months ago](https://wordpress.org/support/topic/hack-pods/#post-17461341)
 * Status: resolved