Skip to content
Advertisement

WordPress SQL: get post category and tags

I want to query WordPress data stored in a MySQL database, in order to get a result with columns:

  1. post_id
  2. category
  3. comma-separated tags

Expected output:

Here’s what I have tried:

As a result, I get the columns I want, with the expected content, but I only get one row.

What am I doing wrong?

Advertisement

Answer

As noted in the comments, I was including an aggregate function, but no “group by” clause.

Now this seems to work (just added the GROUP BY line):

Thank you Strawberry!

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement