Custom SQL Query: Get all posts with category id and a concated list of tags on each post

SELECT DISTINCT p.ID AS id, p.post_title AS title, ( SELECT group_concat(p2.guid SEPARATOR ‘, ‘) FROM wp_postmeta pm LEFT JOIN wp_posts p2 ON pm.meta_value = p2.ID WHERE pm.post_id = p.ID AND pm.meta_key = ‘_thumbnail_id’ AND p2.post_type=”attachment” ) AS image, ( SELECT group_concat(pm.meta_value SEPARATOR ‘, ‘) FROM wp_postmeta pm WHERE pm.post_id = p.ID AND pm.meta_key = ‘views’ … Read more

wpdb query problem to access previous 3 days posts

You are asking for the last three posts ordered by post date, not for the posts from the last three days– ORDER BY post_date DESC LIMIT 3. post_date has a time component to it. It is not just marked with a date. Even so, that LIMIT would restrict the query to last three in the … Read more

wordpress ajax relationship query

Look at the very last part of that query– LIKE ‘%\”17497\”%’. You are searching for any characters, followed by literally “17497”, followed by any characters. I am pretty sure that is not what you want. I think you want any characters, followed by 17497 without the quotes, followed by any characters. That means the meta_query … Read more