Home Forums General Issues writing my wp_query using $wpdb class


writing my wp_query using $wpdb class

  • hi
    i have two custom post type “doctors” and “location” that each “doctors” post related to a “location” post using advanced custom field (relationship )
    i want to write my wp_query code using $wpdb class and pure sql

    $args = array(
    ‘post_type’ => ‘doctors’,
    ‘meta_query’ => array(
    ‘key’ => ‘location’, // name of custom field
    ‘value’ => ‘”‘ . get_the_ID() . ‘”‘,
    ‘compare’ => ‘LIKE’

    $testimonials = new WP_Query( $args );

    please help me

  • Is there a reason why you want to write it in the pure sql?

    but if you wanna know how that WP_Query translate to the sql, you can print out the request.

    $testimonials = new WP_Query( $args );
    echo $testimonials->request; // <- this is the sql statement


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

You must be logged in to reply to this topic.