How to perform query on more than one table (Wordpress)

0

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 to wp_posts ;
  • wp_posts is directly related to wp_term_relationships ;
  • wp_term_relationships is directly related to wp_term_taxonomy ;
  • wp_term_taxonomy is directly related to wp_terms ;
  • But it has a condition ... A query must be done on the wp_usermeta table where meta_value = '_jm_candidate_field_clocknow_user_btn' and meta_key = 'value_1' ;
  • The wp_usermeta table is directly related to wp_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?

    
asked by anonymous 08.02.2017 / 20:15

1 answer

1
SELECT Nome, Titulo, Categoria FROM wp_users
INNER JOIN wp_posts ON wp_users.id = wp_posts.id
INNER JOIN wp_term_relationships ON wp_term_relationships.id = wp_posts.id
INNER JOIN wp_term_taxonomy ON wp_term_taxonomy.id = wp_term_relationships.id
INNER JOIN wp_terms ON wp_terms.id = wp_term_taxonomy.id;

See if this code works. Just remember that I do not even know how tables are, so replace the ids with their table columns.

    
09.02.2017 / 04:39