• I’m trying to write a query that pulls items by the current author for a custom post type, and are flagged with a custom key and value.

    Here’s what I got:

    $sql = "SELECT ID, post_title, post_name, post_status, post_date "
         . "FROM $wpdb->posts "
         . "WHERE post_author = $userdata->ID AND post_type = 'ad_listing' "
         . "AND (post_status = 'publish' OR post_status = 'pending' OR post_status = 'draft') "
         . "AND $wpdb->posts.ID "
         . "AND wpostmeta.meta_key = 'cp_ad_sold' "
         . "AND wpostmeta.meta_value = 'no' "
         . "ORDER BY ID DESC";
    
    $pageposts = $wpdb->get_results($sql);
    
    $i = 1;
    ?>

    I’m trying to figure out how to mash in the “wpostmeta.post_id”; but I can’t figure it out…

  • The topic ‘query help – authors, custom post type and key’ is closed to new replies.