Created
September 21, 2022 14:51
-
-
Save KristaButler/d9548c7d9cea9d984c3edd9e48889aa5 to your computer and use it in GitHub Desktop.
Export Pretty Links with Total and Unique clicks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT l.id, l.url, l.slug, l.name, l.redirect_type, | |
l.track_me, l.nofollow, l.sponsored, l.param_forwarding, | |
gt.meta_value AS google_tracking, d.meta_value AS delay, | |
l.created_at AS created_at, l.updated_at AS last_updated_at , | |
(SELECT GROUP_CONCAT(DISTINCT t.slug ORDER BY t.slug ASC SEPARATOR ',') | |
FROM wp_terms AS t | |
JOIN wp_term_taxonomy AS tt | |
ON t.term_id = tt.term_id | |
AND tt.taxonomy = 'pretty-link-category' | |
JOIN wp_term_relationships AS tr | |
ON tr.term_taxonomy_id = tt.term_taxonomy_id | |
WHERE tr.object_id=p.ID) AS link_categories, | |
(SELECT GROUP_CONCAT(DISTINCT t.slug ORDER BY t.slug ASC SEPARATOR ',') | |
FROM wp_terms AS t | |
JOIN wp_term_taxonomy AS tt | |
ON t.term_id = tt.term_id | |
AND tt.taxonomy = 'pretty-link-tag' | |
JOIN wp_term_relationships AS tr | |
ON tr.term_taxonomy_id = tt.term_taxonomy_id | |
WHERE tr.object_id=p.ID) AS link_tags, | |
(SELECT count(*) FROM wp_prli_clicks as cl WHERE cl.link_id = l.id) AS total_clicks, | |
(SELECT count(*) FROM wp_prli_clicks as cl2 WHERE cl2.link_id = l.id AND cl2.first_click = 1) AS unique_clicks | |
FROM wp_prli_links AS l | |
LEFT JOIN wp_prli_link_metas AS gt | |
ON l.id = gt.link_id AND gt.meta_key = 'google_tracking' | |
LEFT JOIN wp_prli_link_metas AS d | |
ON l.id = d.link_id AND d.meta_key = 'delay' | |
JOIN wp_posts AS p | |
ON p.ID = l.link_cpt_id | |
WHERE l.link_status='enabled' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment