【问题标题】:How to get Wordpress attachments to work for existing images inside the Media Library?如何让 Wordpress 附件适用于媒体库中的现有图像?
【发布时间】:2014-10-28 08:17:03
【问题描述】:

我想在单独的页面上显示每个 Wordpress 帖子中的图像。

当使用get_children(或get_posts)时,'post_type' => 'attachment' 仅在我刚刚将图像(通过 WP 的“添加媒体 > 上传文件”)上传到该特定帖子时才有效。

如果我将现有图像添加到我的 WP MEDIA LIBRARY 中已经存在的帖子中,它将不起作用)。

'attachment' 是否可以用于现有(已上传)图像?

查看我的测试功能:

function echo_first_image($postID){
    $args = array(
        'post_type' => 'attachment',
        'post_parent' => $postID
    );
    $attachments = get_children( $args );
    if($attachments){
        echo'YES';   // test answer
    }else{
        echo'NO';   // test answer
    }
}

编辑:作为“附件”的每个“post_type”都有一个“post_parent”——这是否意味着附件只能有一个父级?

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    目前,Wordpress 4.1 不包括多父附件,因为数据库关系是一对一的,而不是一对多的。您必须找到一个插件,或者编写自己的插件来解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 2020-09-23
      • 2015-12-29
      • 1970-01-01
      • 2019-11-26
      • 2015-05-07
      • 1970-01-01
      相关资源
      最近更新 更多