I was afraid you would say something like that. Well I suggest you put in a feature request so the debugger can be modified to show everything the looper has access to kind of like using var_dump
in PHP, maybe add a key modifier or something to the Dynamic Content code.
For anyone that is in the same situation I figure out some code that will spit out all the MEC event info and since all my dates are repeating it works for my needs. I may be excluding some columns/fields but you can test the MYSQL section in something like PHPMyAdmin and just fix the table/column/filed names to match your table names (fi you changed your “wp_” prefix or need more data) and add today’s date just for testing. Also my code pulls all the “Custom Fields” and spits them out as “mec_fields_1”, “mec_fields_2”, “mec_fields_3”… and so on.
Place this code in Functions.php and then setup a custom Looper Provider and use the name uptournaments
or rename uptournaments
in the function cs_looper_custom_uptournaments
to whatever you want:
// Function to parse the serialized mec_fields data and extract the keys and values
function parse_mec_fields($data) {
$parsed_data = [];
// Unserialize the data
$unserialized_data = unserialize($data);
if (is_array($unserialized_data)) {
foreach ($unserialized_data as $key => $value) {
$parsed_data['mec_fields_' . $key] = $value;
}
} else {
// If the data is not serialized, assume it's a single value
$parsed_data['mec_fields'] = $data;
}
return $parsed_data;
}
// The function to fetch events and parse mec_fields
add_filter('cs_looper_custom_uptournaments', function ($result) {
$current_date = date('Ymd');
global $wpdb;
// Fetch events that are today or have repeating date equal to today or in the future
$query = $wpdb->prepare("
SELECT p.ID, p.post_title, p.post_content, p.post_name, pm.*,
d.*, FROM_UNIXTIME(d.tstart) AS start_datetime,
p2.guid AS featured_image,
MAX(CASE WHEN pm3.meta_key = 'mec_fields' THEN pm3.meta_value END) AS mec_fields
FROM {$wpdb->posts} AS p
INNER JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id
LEFT JOIN {$wpdb->prefix}mec_dates AS d ON p.ID = d.post_id
LEFT JOIN {$wpdb->postmeta} AS pm3 ON p.ID = pm3.post_id AND pm3.meta_key LIKE 'mec_fields%'
LEFT JOIN {$wpdb->postmeta} AS pm2 ON p.ID = pm2.post_id AND pm2.meta_key = '_thumbnail_id'
LEFT JOIN {$wpdb->posts} AS p2 ON pm2.meta_value = p2.ID
WHERE d.dstart >= %s AND p.post_type = 'mec-events' AND p.post_status = 'publish'
GROUP BY d.ID
ORDER BY d.dstart ASC, d.tstart ASC
", $current_date);
// Run the custom query
$results = $wpdb->get_results($query, ARRAY_A);
// Parse the serialized mec_fields data for each result
foreach ($results as &$result) {
if (isset($result['mec_fields'])) {
$parsed_fields = parse_mec_fields($result['mec_fields']);
$result = array_merge($result, $parsed_fields);
unset($result['mec_fields']);
}
}
return $results;
}, 10, 2);
Here is a the MySQL cleaned up so you can run it in something like PHPMyAdmin… Change 20230726 (YYYYMMDD) to today’s date:
SELECT p.ID, p.post_title, p.post_content, p.post_name, pm.*,
d.*, FROM_UNIXTIME(d.tstart) AS start_datetime,
p2.guid AS featured_image,
MAX(CASE WHEN pm3.meta_key = 'mec_fields' THEN pm3.meta_value END) AS mec_fields
FROM wp_posts AS p
INNER JOIN wp_postmeta AS pm ON p.ID = pm.post_id
LEFT JOIN wp_mec_dates AS d ON p.ID = d.post_id
LEFT JOIN wp_postmeta AS pm3 ON p.ID = pm3.post_id AND pm3.meta_key LIKE 'mec_fields%'
LEFT JOIN wp_postmeta AS pm2 ON p.ID = pm2.post_id AND pm2.meta_key = '_thumbnail_id'
LEFT JOIN wp_posts AS p2 ON pm2.meta_value = p2.ID
WHERE d.dstart >= 20230726 AND p.post_type = 'mec-events' AND p.post_status = 'publish'
GROUP BY d.ID
ORDER BY d.dstart ASC, d.tstart ASC
Here are some of the Dynamic codes I am using (My code takes the repeating start date/time and turns it into a format the looper can understand and renames it “start_datetime”):
{{dc:looper:field key="featured_image"}}
{{dc:looper:field key="post_title"}}
{{dc:looper:field key="start_datetime" type="time" format="l gA"}}
{{dc:looper:field key="start_datetime" type="date" format="M j"}}
{{dc:looper:field key="mec_fields_1"}}
{{dc:looper:field key="mec_fields_2"}}
{{dc:looper:field key="mec_fields_3"}}
{{dc:looper:field key="mec_fields_4"}}