I am having an issue that i couldn't find on google and elsewhere. To put problem in the context. I am making a wordpress site where user can put their tutor listing for giving a tutorials, and i am implementing the system of evaluation of the tutors them self and their listening. So I have tutor_listing post type and each tutor_listing has a 'post_score' meta value, and each tutor (user who puts his tutorials) has user_meta value called 'user_points'.
So I need a WP_Query that will get from the database all published tutor_listing but sorted by (post_score + user_points). Just to emphasis 'post_score' is a post_meta of the post_type tutor_listing and 'user_points' is user_meta of author of that post (tutor_listing). Also i need that value to show in the loop.
I can get all the tutor_listing by
$args = array( 'post_type' => 'job_listing', 'post_status' => 'publish' ); $query = new WP_Query( $args );
I can get the result from the custom wordpress sql query like this:
SELECT p1.ID, p1.post_author, p1.post_title, p1.post_date, (um1.meta_value + pm1.meta_value) AS total_score FROM $wpdb->posts p1 JOIN $wpdb->users u1 ON (p1.post_author = u1.ID) JOIN $wpdb->usermeta um1 ON (um1.user_id = u1.ID) JOIN $wpdb->postmeta pm1 ON (pm1.post_id = p1.ID) WHERE p1.post_type = 'tutor_listing' AND p1.post_status = 'publish' AND um1.meta_key = 'user_points' AND pm1.meta_key = 'post_score'";
Can WP_Query provide such a functionality? I need WP_Query to use its all extra functionality like pagination ect. Or is there a way i could all the result done with the my custom sql give to WP_Query object?