Support

Account

Home Forums General Issues writing my wp_query using $wpdb class

Helping

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(
    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
    

    Cheers

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

The topic ‘writing my wp_query using $wpdb class’ is closed to new replies.