Php 从Wordpress外部检索Wordpress附件

Php 从Wordpress外部检索Wordpress附件,php,mysql,wordpress,Php,Mysql,Wordpress,我希望能够抓取已附加到Wordpress帖子的照片,并独立于我的Wordpress安装进行显示。 我的用法是在Wordpress安装范围之外的页面上显示最新文章的摘录(比如,mysite.com/blog/是Wordpress存在的地方,但在mysite.com/index.php上显示最新文章的摘录),现在我希望能够将图像附加到文章上(不一定是文章作者,更确切地说,是任意附加的图像…甚至可能没有显示在文章中…只是附加到它上) 我用我自己的类(连接到wordpress数据库)抓取了最新文章的摘录

我希望能够抓取已附加到Wordpress帖子的照片,并独立于我的Wordpress安装进行显示。

我的用法是在Wordpress安装范围之外的页面上显示最新文章的摘录(比如,
mysite.com/blog/
是Wordpress存在的地方,但在
mysite.com/index.php
上显示最新文章的摘录),现在我希望能够将图像附加到文章上(不一定是文章作者,更确切地说,是任意附加的图像…甚至可能没有显示在文章中…只是附加到它上)

我用我自己的类(连接到wordpress数据库)抓取了最新文章的摘录,并对其运行我自己的SQL查询。这很简单。问题是,我看不出附加的图像与文章有什么关联

在查看Wordpress代码本身时,我看到了以下功能:

function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false )  {
        if ( !empty( $deprecated ) )
            _deprecated_argument( __FUNCTION__, '2.5' );

        if ( $fullsize )
            echo wp_get_attachment_link($id, 'full', $permalink);
        else
            echo wp_get_attachment_link($id, 'thumbnail', $permalink);
     }
看起来它可能会抓取一个附加的图像,但我仍然不知道如何(我也不知道如何从Wordpress之外使用这个函数)

在Wordpress安装之外,如何抓取附在Wordpress帖子上的图像进行显示

额外…以下是我如何首先获取帖子文本:

SELECT * FROM wp_posts p
            INNER JOIN wp_term_relationships rs ON p.ID = rs.object_id
            INNER JOIN wp_term_taxonomy tt ON tt.term_id = rs.term_taxonomy_id
            WHERE rs.term_taxonomy_id IN ($termId) AND p.post_type = 'post'
            AND p.post_status='publish'
但是,由于我在数据库中没有看到任何关于附加照片的信息,我不知道如何抓取它。有什么想法吗

更多额外信息…下面是我如何从Wordpress“循环”中抓取这样一张照片的方法:


当然,我不能完全从Wordpress之外调用它。

你试过使用吗?你可以创建一个名为“attached_image”或任何你想要的自定义字段,带有你想要附加的图像的url。然后你只需从数据库中检索该信息。我想它们会保存在表“yourprefix_Posteta”中其中包含“post_id”(您的帖子)和“meta_key”(在我的示例中为“attached_image”)。

附件列在wp_posts数据库中。它们的关联方式如下:
post_type='attachment',post_parent=post_id
。但我想您知道这一点

编辑
此外,您还可以从wordpress的主目录中包括
wp blog header.php
来访问wordpress类和函数。现在您可以使用本机wordpress函数了,请查看您似乎在问题中回答了自己的问题。post_type='attachment'和post_parent='$post->ID'。您缺少什么?我可以从Wordpress内部执行此操作,但不要从Wordpress外部运行的自定义脚本执行此操作(尽管看起来,使用您建议的解决方案,我将能够…thx)。
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID ); 
$attachments = get_posts($args);
if ($attachments) {
    foreach ( $attachments as $attachment ) {
        echo apply_filters( 'the_title' , $attachment->post_title );
        the_attachment_link( $attachment->ID , false );
    }
}