Skip to content

Instantly share code, notes, and snippets.

@miguelcperez
Last active March 19, 2018 20:47
Show Gist options
  • Save miguelcperez/32a5ba6260a7516b28fab96326a83445 to your computer and use it in GitHub Desktop.
Save miguelcperez/32a5ba6260a7516b28fab96326a83445 to your computer and use it in GitHub Desktop.
Query Posts relacionados por TAG
SELECT c.post_id, c.post_c FROM (
SELECT b.post_id, COUNT(b.post_id) AS post_c FROM(
SELECT post_id, tag_id FROM post_tag
WHERE tag_id IN (SELECT tag_id FROM post_tag WHERE post_id = 1)) AS b
GROUP BY b.post_id
) AS c
WHERE c.post_c >= 2
-- c.post_c >=2 -> cantidad de TAGS en común
-- post_id -> id del POST
@codepainkiller
Copy link

Directo a WP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment