Im trying to run a sub-query that based on one of the main query values but i always get 0 as VALUE. This is my query :
SELECT ID,(
SELECT COUNT( * )
FROM `post_meta`
WHERE `post_id`
IN (
SELECT `ID`
FROM `wp_posts`
WHERE `post_title` = posts.ID
)
) AS counter
FROM wp_posts;
if i run only the sub-query with id number instead of posts.ID it returns a good value.
wp_posts.IDdue to your comment on jjs9534 answer. So, how can you havewp_posts.ID = post_meta.post_idand alsowp_posts.ID = post_meta.post_title? That just doesn't seem right.post_title= posts.ID topost_title= 5161 it works fine, so this part is ok,post_meta.post_idis always populated then you couldn't you just leave off thewp_posts.ID = post_meta.post_titlecompletely. Part of the problem might be your comparing two different data types.