Home Forums General Issues sql query


sql query

  • Dear Support
    I really ask you for help
    I really need to compose a sql query so that to get all posts and all the fields they contain for the WpDataTable plugin

    my database is mysql

  • I think that’s a pretty big ask. Not to mention we don’t know how many custom fields you have or what they’re called!

    If I were you, I’d look at the wp_query

    I’d ensure you query the correct post type and I’d look the OR operator, like this example:

    $args = array(
        'post_type'  => 'product',
        'meta_query' => array(
            'relation' => 'OR',
                'key'     => 'color',
                'value'   => 'blue',
                'compare' => 'NOT LIKE',
                'key'     => 'price',
                'value'   => array( 20, 100 ),
                'type'    => 'numeric',
                'compare' => 'BETWEEN',
    $query = new WP_Query( $args );

    Once you’ve added ALL of your possible custom fields and the output displays something, you could look to output your wp_query in SQL using:

    $customPosts = new WP_Query($yourArgs);
    echo "Last SQL-Query: {$customPosts->request}";

    That hopefully will give you the SQL you need.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.