How do I do a QUERY
in the database in 5 different tables and return the values I want, eg:
I am performing a search system (my first) and need to capture the following values: Name of Applicant, Title of Curriculum and Category of Vacancy. Now let's get information:
- The name of the candidate is in the
wp_users
table; - The title of the curriculum is in the table
wp_posts
; - The job category is in the
wp_terms
table; -
wp_users
is directly related towp_posts
; -
wp_posts
is directly related towp_term_relationships
; -
wp_term_relationships
is directly related towp_term_taxonomy
; -
wp_term_taxonomy
is directly related towp_terms
; - But it has a condition ... A query must be done on the
wp_usermeta
table wheremeta_value = '_jm_candidate_field_clocknow_user_btn'
andmeta_key = 'value_1'
; - The
wp_usermeta
table is directly related towp_users
wp_usermeta
- > wp_users
- > wp_posts
- > wp_term_relationships
- > wp_term_taxonomy
- > wp_terms
ThequeryI'mdoingisnotreturningvalues:
$resultados=$wpdb->get_results("SELECT $wpdb->users.display_name, $wpdb->posts.post_title, $wpdb->terms.name, $wpdb->usermeta.meta_key, $wpdb->usermeta.meta_value
FROM $wpdb->usermeta
WHERE $wpdb->usermeta.meta_key = '_jm_candidate_field_clocknow_user_btn' AND $wpdb->usermeta.meta_value = 'value_2'
INNER JOIN $wpdb->users ON $wpdb->usermeta.user_id = $wpdb->users.ID
INNER JOIN $wpdb->posts ON $wpdb->posts.post_author = $wpdb->users.ID
INNER JOIN $wpdb->term_relationships ON $wpdb->term_relationships.object_id = $wpdb->posts.ID
INNER JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->term_relationships.term_taxonomy_id
INNER JOIN $wpdb->terms ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_taxonomy_id;" );
Is the logic wrong?