I have site http://change.is, i migrate it to new server. Now one of the sql query is showing odd result. The query is below:
SELECT distinct group_concat(pm.meta_value separator ' ') as composer, group_concat(pm.meta_value separator '-') as composer_link FROM $wpdb->postmeta pm where (pm.meta_key='composer_fname_value' OR pm.meta_key='composer_lname_value') and pm.post_id in (SELECT p.ID FROM $wpdb->posts p where p.post_type='quote' AND p.post_status='publish') group by pm.post_id order by group_concat(IF(pm.meta_key='composer_lname_value', pm.meta_value,'')) ASC
Explanation:
I have meta fields like author firstname, author lastname (what i needed in this query) in the admin section for custom post type “quote”. Before migrating to new server, this query is picking the author firstname & then author last name. So output become like ( Seteve Jobs, Jeff Bezos). After migrating, i added new post for this custom type ‘quote’. But now it is picking author last name & then author first name So output becomes like ( Diamandis Peter )
Point, it is picking this only for new post added, for old post in the database, it is coming fine.
Please help on this, or provide alternative query
It looks like you want to order the pm.meta_values(s) in the
group_concatdepending on their associated pm.meta_key. When pm.meta_key=’composer_lname_value’, the value should come first.In this case, the easiest solution seems to use the optional ORDER BY clause of
group_concat:Maybe that’s what you wanted to achieve with the ORDER BY at the end of the query, but this sorts output lines, not contents inside the same line.