Support

Account

Home Forums General Issues Looking for a SQL Query to get posts and AC fields

Helping

Looking for a SQL Query to get posts and AC fields

  • Hi,

    I’ve an ap getting datas in my WP mysql database.
    I’m looking for an SQL query to get all posts of ‘books’ custom post type. And this query have to return all posts with all acf metas.

    A sql like this ‘SELECT * FROM posts WHERE post_type = ‘events’

    I’m newbie with SQL queries… can you help me ?

  • There isn’t a query that you can run that will select posts and return all meta values associated with it. This requires multiple queries. First the one you have above. Then you need to loop over that return and do a query like:

    
    // please note that this may not be the best way to do this query, 
    // I am not an SQL expert.
    
    "SELECT * FROM postmeta WHERE post_id = '{$post_id}'
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.