多亏了@Pieter Goosen的提示,我才能够完成这项工作。为了防止其他人关注或将来参考,我进一步使用了这段代码,所以现在我正在自定义分类法中按类别为所有相关帖子创建一个缩略图ID数组。然后,我将此数组传递给mla\\U gallery短代码,以动态调用具有链接到父页面的缩略图的相关项目列表。演示:http://ecominded.wpengine.com/landscape-design-construction/landscape-construction/
//get all the post ids of current projects
$post = get_post( $post->ID );//get current post
// get the terms related to post
$args = array(\'orderby\' => \'date\', \'order\' => \'ASC\', \'fields\' => \'slugs\');
$terms = wp_get_object_terms( $post->ID, \'project_category\' , $args);
$qry_args = array(
\'post_status\' => \'publish\', // optional
\'post_type\' => \'project\', // Change to match your post_type
\'tax_query\' => array(
array(
\'taxonomy\' => \'project_category\',
\'field\' => \'slug\',
\'terms\' => $terms,
),
),
\'posts_per_page\' => 12, // # of posts
\'fields\' => \'ids\',
);
$all_posts = new WP_Query( $qry_args );
$post_thumbnail_ids = array();//initialize array
foreach((array) $all_posts->posts as $id) {
$post_thumbnail_ids[] = get_post_thumbnail_id( $id );
}
$string_ids = implode( \',\', $post_thumbnail_ids );//convert to string for shortcode
echo do_shortcode(\'[mla_gallery post_parent=any posts_per_page=12 ids=\'. $string_ids .\' ]\');
echo do_shortcode(\'[mla_gallery post_parent=any posts_per_page=12 ids=\'. $string_ids .\' mla_output=paginate_links]\');