最好的SQL解决方案,
从wp\\U post中搜索ID
SELECT * FROM wp_posts WHERE post_status=\'publish\'
找到元内容
SELECT * FROM wp_postmeta WHERE meta_key=\'_thumbnail_id\' AND post_id=MyID
使用缩略图ID,在wp\\U Posteta文件中再次搜索
SELECT * FROM wp_postmeta WHERE meta_key=\'_wp_attached_file\' AND post_id=MyID
这里有一个例子。
$query = mysql_query("SELECT * FROM wp_posts WHERE post_status=\'publish\' ORDER BY id DESC LIMIT 6") or die(mysql_error());
$json=\'{ "Blog" : [ \';
while($row =mysql_fetch_array($query)){
$queryMeta=mysql_query("SELECT * FROM wp_postmeta WHERE meta_key=\'_thumbnail_id\' AND post_id=$row[ID]") or die(mysql_error());
$f=mysql_fetch_array($queryMeta);
$value=$f[meta_value];
$queryMeta2=mysql_query("SELECT * FROM wp_postmeta WHERE meta_key=\'_wp_attached_file\' AND post_id=$value") or die(mysql_error());
$f2=mysql_fetch_array($queryMeta2);
$value=$f2[meta_value];
$json.=\'{"id" : "\'.$row[ID].\'" , "date" : "\'.$row[post_date].\'", "title" :"\'.$row[post_title].\'", "link" : "\'.$row[guid].\'" , "image" :"https://dartesanos.com/blog/wp-content/uploads/\'.$value.\'" },\';
}
$json=substr($json,0,-1);
echo $json ."]}";