Docs & Support

Learn about all Business Directory’s features and get support from our amazing customer success team.

Customizations
How to export listings using SQL

How to export listings using SQL

Exporting entries from Business Directory Plugin is easiest using the built in exporting options. If you’d like to get the listings using SQL, here’s an example to get you started.

SELECT t.name 'Category', p.post_title 'Company', GROUP_CONCAT(pm.meta_value) 'Contact', p.post_content 'Description'
FROM wp_terms t, wp_term_taxonomy tx, wp_posts p, wp_postmeta pm, wp_term_relationships tr
WHERE pm.post_id = p.ID AND
tr.object_id = p.id AND
p.post_type = 'wpbdp_listing' AND
pm.meta_key in ('_wpbdp[fields][6]','_wpbdp[fields][8]','_wpbdp[fields][10]','_wpbdp[fields][11]','_wpbdp[fields][12]') AND
tr.term_taxonomy_id = tx.term_taxonomy_id AND
tx.term_id = t.term_id
GROUP BY pm.post_id order by t.name, pm.meta_key

Explanation:
Line 1: pm.meta_value represents the fields that are in the form used for entering the directory date, e.g., address, city, state, etc.
the GROUP_CONCAT command strings together the data from individual rows into a string separated by a comma.
Line 2: These are the tables that hold the data to be extracted
Line 3-8: These are the columns used to link the tables together and also contain the data to be extracted. Note that the meta_key field contents may differ in your case; the above are the values that correspond to the address, city, state, zip, etc. in my database.
Line 9: This command groups the extracted data by post_id and sorts the output by category and meta_key (address, city, state, etc.)

Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2010-2025 S11 Directories, LLC.

    Complete your purchase
    Special offer unlocked.
    Get 55% OFF!
    Complete Purchase
    Join 20,000+ using Business Directory Plugin to build website directories fast. Get Started