简体   繁体   English

通过SQL查询从WordPress获取帖子数据

[英]get post data from wordpress by sql query

I want to get wordpress post data and get wp_attached_file from wp_postmeta table this is my sql query 我想获取wordpress发布数据并从wp_postmeta表中获取wp_attached_file,这是我的SQL查询

$query= mysql_query("SELECT wp_posts.ID,wp_posts.post_title,wp_posts.post_date,wp_postmeta.meta_value 
                FROM wp_posts

                  JOIN wp_term_relationships
                        ON wp_term_relationships.object_id = wp_posts.ID

                    JOIN wp_postmeta
                        ON wp_postmeta.post_id = wp_posts.ID

                WHERE wp_posts.post_date > '$before7' 
                AND wp_posts.post_status = 'publish' 
                AND wp_posts.post_type = 'post' 
                AND wp_term_relationships.term_taxonomy_id = '$cat' 
                AND wp_postmeta.meta_key = '_wp_attached_file' 
                ORDER BY wp_posts.post_date DESC LIMIT 10");

it give me nothing but if I removed this line from where clause 它没有给我任何东西,但是如果我从where子句中删除了这一行

AND wp_postmeta.meta_key = '_wp_attached_file'

it works but I need this line to get wp_attached_file 它有效,但是我需要这一行来获取wp_attached_file

so what is wrong with mysql query 那么mysql查询怎么了

确保值_wp_attached_file的wp_postmeta.meta_key确实存在,然后匹配可能存在一些问题,请尝试修剪两者均导致隐藏字符

  AND trim(wp_postmeta.meta_key)  = trim('_wp_attached_file')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM