Last active
March 19, 2018 20:47
-
-
Save miguelcperez/32a5ba6260a7516b28fab96326a83445 to your computer and use it in GitHub Desktop.
Query Posts relacionados por TAG
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Directo a WP!