-1

I have for the example two table (person and skill).

TABLE PERSON 
id,
First_name,
Last_name,
Mail

TABLE SKILL 
id,
Name,
level
id_person

Can I in SQL have the result below :

id | First_name | Last_name | Mail | concat(SKILL 1 name, SKILL 1 level) | concat(SKILL 2 name, SKILL 2 level) etc..

And to complicate the thing a little, i just want some skill, not all.

I see this POST but, i don't want to concat the result (there is a ton of skill).

It's possible ?

Thx


For further information, i want to select all the post_meta of a custom post in Wordpress. I have first table post (with title, date etc) and table wp_postmeta (with one line per meta) So, I need a request to select in one row the information of the post and the meta : ID, TITLE, LAST_UPDATE, CONCAT (META_key1, META_value1), CONCAT (META_key1, META_value1)

So I have this two tables:

  • wp_posts
  • post_id, post_author, post_date, post_date_gmt, post_content, post_title, post_type
  • wp_postmeta
  • meta_id, post_id, meta_key, meta_value

I try this

SELECT * FROM wp_posts LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id WHERE post_type = 'user' 

In result i Have mutliple row. I just want one

Community
  • 1
  • 1

1 Answers1

0

I found the answer at my question.

I must use the object WP_Query, i hope the code below help other people

global $wpdb;
$args = array('post_type' => 'user');
$result_post = new WP_Query($args);

if ( $result_post->have_posts() ) {
    echo '<ul>';
    while ( $result_post->have_posts() ) {
        $result_post->the_post();
        echo '<li>' . get_the_title() . '</li>';
        echo '<li>' . the_meta() . '</li>';
        echo '<li>' . get_post_meta(get_the_id(),"name",true) . '</li>';
    }
    echo '</ul>';