0

This is my query

SELECT P.ID, P.post_title, P.post_content, P.post_author,
MAX(IF(PM.meta_key = 'ex_latitude', PM.meta_value, NULL)) AS lat,
MAX(IF(PM.meta_key = 'ex_longitude', PM.meta_value, NULL)) AS lng    

FROM wp_posts AS P
LEFT JOIN wp_postmeta AS PM on PM.post_id = P.ID
WHERE P.post_type = 'post' and P.post_status = 'publish'
ORDER BY P.ID DESC   

Result only one post data row

+-----+------------+--------------+-------------+-----------+---------------+
| ID  | post_title | post_content | post_author |    lat    |      lng      |
+-----+------------+--------------+-------------+-----------+---------------+
| 10  | Post Title | Post Content |           1 | 56.00078  | 26.45677      |
+-----+------------+--------------+-------------+-----------+---------------+

But how return all posts?

  • Are you sure that the query was supposed to return more than one row? – Sally CJ Mar 12 at 16:14
  • Yes, have more than 1000 posts with this meta keys – KingStakh Mar 12 at 17:20
  • You could easily achieve the results using a standard WP_Query query. Why don't you use it? – Sally CJ Mar 13 at 7:43
  • Because I planned to use outside the WordPress. – KingStakh Mar 13 at 10:57
  • So if I understand it properly, you want to get all the posts having the ex_latitude or ex_longitude metadata, right? – Sally CJ Mar 13 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.