I know this might be a simple question but can someone explain to me how to query the WP database and pull in all the "meta_key" and "meta_value" from "post_id" into an array? I have looked at code and tutorials but I still cant figure out how to make it work correctly.

1 Answer 1


You can use get_post_meta( $post_id ) to retrieve all of the meta for a post. It will give you more than you need but you can filter it out after.

Here is the code reference - https://developer.wordpress.org/reference/functions/get_post_meta/

  • It never ceases to amaze me how you can try something and once you post it works. I had tried the same code but couldn't get it to work before posting... "Power of Posting" right? Feb 2, 2016 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.