Fixed $wpdb usage in associated_posts