-1

I have a directory website running on wordpress. I have a lot the the business listings stored in the postmeta table. I am tasked to retrieve that data to be exported in csv file using either SQL queries or other means.

Is there way to write SQL queries to retrieve the data inside the postmeta table in wordpress database?

Kevin
  • 551
  • 1
  • 9
  • 28

1 Answers1

0

There is rarely a need to directly access the database in WordPress, you can get a post meta with the native get_post_meta() function which retrieves a post meta field for the given post ID

(See here: https://developer.wordpress.org/reference/functions/get_post_meta/)

Example:

Get data for all keys (default):

<?php $meta = get_post_meta($post_id); ?>

Get post meta for a single key:

<?php $key_1 = get_post_meta($post_id, 'key_1'); ?>

You might need to filter out unwanted meta keys starting with an underscore.

Hillel
  • 811
  • 2
  • 7
  • 19