这里需要一点帮助,请,我试图从wp\u posttea获取信息分配给一个名为acf的插件的id\u post,结构如下:
+------------+----------+-----------------------------------------+-----------------------------+
| meta_id | post_id | meta_key | meta_value |
+-----------------------------------------------------------------+-----------------------------+
| 134704 | 462 | rates_group_0_rates_group_title | Center/East Programs |
| 134705 | 462 | rates_group_1_rates_group_title | South/Center Programs |
| 134706 | 462 | rates_group_2_rates_group_title | East Center Program |
| 134707 | 462 | rates_group_3_rates_group_title | South/East Center Programs |
| 134708 | 462 | rates_group_0_rates_group_second_title | 4 Day Itineraries |
| 134709 | 462 | rates_group_1_rates_group_second_title | 5 Day Itineraries |
| 134710 | 462 | rates_group_2_rates_group_second_title | 6 Day Itineraries |
| 134711 | 462 | rates_group_3_rates_group_second_title | 7 Day Itineraries |
+------------+----------+-----------------------------------------+-----------------------------+
这是我的sql查询:
SELECT
post.ID,
post.post_title,
meta1.meta_value,
meta2.meta_value
FROM wp_posts post
INNER JOIN wp_postmeta meta1 ON meta1.post_id = post.ID AND meta1.meta_key like 'rates_group_%_rates_group_title'
INNER JOIN wp_postmeta meta2 ON meta2.post_id = post.ID AND meta2.meta_key like 'rates_group_%_rates_group_second_title'
WHERE
post.post_type = 'portfolio'
AND post.ID=462
GROUP BY meta1.meta_key
结果如下:
+--------+------------+-----------------------------+--------------------------+
| ID | post_title | meta_value | meta_value1 |
+------------------------------------------------------------------------------+
| 462 | Title | Center/East Programs | 4 Day Itineraries |
| 462 | Title | South/Center Programs | 4 Day Itineraries |
| 462 | Title | East Center Program | 4 Day Itineraries |
| 462 | Title | South/East Center Programs | 4 Day Itineraries |
+--------+------------+-----------------------------+--------------------------+
这是预期的结果:
+--------+------------+-----------------------------+--------------------------+
| ID | post_title | meta_value | meta_value1 |
+------------------------------------------------------------------------------+
| 462 | Title | Center/East Programs | 4 Day Itineraries |
| 462 | Title | South/Center Programs | 5 Day Itineraries |
| 462 | Title | East Center Program | 6 Day Itineraries |
| 462 | Title | South/East Center Programs | 7 Day Itineraries |
+--------+------------+-----------------------------+--------------------------+
这是一个使用2个字段的示例 rates_group_title
以及 rates_group_second_title
但是应该有更多的字段,但是结果应该总是显示在4行中。
谢谢你的帮助。
暂无答案!
目前还没有任何答案,快来回答吧!