Mysql SELECT posts

时间:2015-08-08 作者:Valeriy Donika

如何通过MYSQL从语言为“en”和“ru”的帖子中获取帖子

我有这个问题

$sql = "SELECT p1.*, wm2.meta_value 
  FROM wp_posts p1 
  LEFT JOIN wp_postmeta wm1 ON ( wm1.post_id = p1.ID 
  AND wm1.meta_value IS NOT NULL 
  AND wm1.meta_key = \'_thumbnail_id\' ) 
  LEFT JOIN wp_postmeta wm2 ON ( wm1.meta_value = wm2.post_id 
  AND wm2.meta_key = \'_wp_attached_file\' 
  AND wm2.meta_value IS NOT NULL ) 
  WHERE p1.post_status= \'publish\' AND p1.post_type=\'post\' ORDER BY p1.post_date DESC Limit 3";
我使用WPML插件。

2 个回复
SO网友:Jose Carlos Ramos Carmenates

我决定创建SQL查询:

SELECT posts.post_title, posts.post_content, trans.element_type,
trans.language_code
FROM wp_posts AS posts

INNER JOIN wp_icl_translations AS trans
ON posts.ID = trans.element_id

INNER JOIN wp_postmeta AS meta
ON posts.ID = meta.post_id

WHERE trans.element_type = \'post_product\'
AND trans.language_code = \'de\'
仅当您需要post\\u meta上的某些内容时,才会添加此项:

...
INNER JOIN wp_postmeta AS meta
ON posts.ID = meta.post_id
...
我的解决方案是通过语言获取所有帖子trans.language_code = \'de\', trans.language_code = \'es\', trans.language_code = \'en\' ...

SO网友:Valeriy Donika

$sql = "SELECT p1.*, wm2.meta_value 
                        FROM wp_posts p1 
                        JOIN wp_icl_translations t
                        ON p1.ID = t.element_id 
                        LEFT JOIN wp_postmeta wm1 ON ( wm1.post_id = p1.ID 
                        AND wm1.meta_value IS NOT NULL 
                        AND wm1.meta_key = \'_thumbnail_id\' ) 
                        LEFT JOIN wp_postmeta wm2 ON ( wm1.meta_value = wm2.post_id 
                        AND wm2.meta_key = \'_wp_attached_file\' 
                        AND wm2.meta_value IS NOT NULL ) 
                        WHERE p1.post_status= \'publish\' 
                        AND p1.post_type=\'post\' 
                        AND t.element_type=\'post_post\'
                        AND t.language_code=\'ru\' 
                        ORDER BY p1.post_date DESC 
                        Limit 0, 3";
用拇指点击lang是ru的最后3篇帖子

结束

相关推荐

定制WordPress+PHP+MySQL+AJAX表单,提交事件不被Java捕获,但将数据发布到数据库

我正在构建一个小表单,允许用户在vanilla Wordpress用户管理系统之外更新他们的联系信息。我计划使用一个简单的积垢设置,并加入一些卫生设施。我已经使用$wpdb函数构建了初始的插入/创建函数,并且表单确实正确地写入了数据库。然而,当我提交表单时,我的Javascript没有被调用。Javascript文件没有捕获提交事件,表单只是将数据直接发布到PHP处理器文件。我在这里挠头。问题概述,逐场:1。表单提交,但用户被重定向到一个包含JSON编码的数组数据的页面。2、从未接触过包含我的错误处理和A