0

我正在将自定义元添加到我的附件文件中,并希望将每个附件的三个页面 ID 存储在一个数组中。

然后,我想为该数组中存在 ID 的附件执行 get_posts,但该数组返回为空。

$p_downloads = get_posts(array(
    'post_type'      => 'attachment',
    'post_mime_type' => 'application/pdf',
    'meta_key'       => 'bv_media_meta_procedure',
    'meta_value'     => $post->ID,
    'orderby'        => 'title',
    'order'          => 'ASC',
    'posts_per_page' => -1
));

目前,其中一个附件的 bv_media_meta_procedure 的 post meta 如下所示:

array (size=1)
  0 => 
    array (size=3)
      0 => string '238' (length=3)
      1 => string 'null' (length=4)
      2 => string 'null' (length=4)

所以在 238 的页面 ID 上,我希望看到在 get_posts 函数中返回的附件。

但是它返回的是空的,怎么会呢?

4

1 回答 1

0

我在阅读这篇文章后发现:http: //brianshim.com/webtricks/query-wordpress-custom-field-array/

自定义元存储为序列化数组,通过稍微更改 get_posts 函数,现在返回正确的结果。

$p_downloads = get_posts(array(
    'post_type'      => 'attachment',
    'post_mime_type' => 'application/pdf',
    'meta_key'       => 'bv_media_meta_procedure',
    'meta_value'     => '"'.$post->ID.'"',
    'meta_compare'   => 'LIKE',
    'orderby'        => 'title',
    'order'          => 'ASC',
    'posts_per_page' => -1
));
于 2018-02-13T10:56:28.437 回答