我通过ACF创建了博客帖子和自定义帖子类型之间的关系,其中包含员工档案。通过这种关系,我可以显示指向该员工个人资料的链接,该员工是一篇文章的作者。
我现在想显示员工在其个人资料中创建的帖子列表。我找到了一个code 就是这样。不幸的是,每当我为一名员工分配5篇以上的博客帖子时,下一篇就看不见了。你能帮我调整代码,在新行中显示5篇以上的帖子吗?
<div class="author-content">
<?php
/*
* Query posts for a relationship value.
* This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
*/
$documents = get_posts(array(
\'post_type\' => \'post\',
\'meta_query\' => array(
array(
\'key\' => \'our_people_author\', // name of custom field
\'value\' => \'"\' . get_the_ID() . \'"\', // matches exaclty "123", not just 123. This prevents a match for "1234"
\'compare\' => \'LIKE\'
)
)
));
?>
<?php if( $documents ): ?>
<ul class="table-author">
<?php foreach( $documents as $document ): ?>
<li class="singleauth-list">
<a href="<?php echo get_permalink( $document->ID ); ?>"><img src="<?php echo get_the_post_thumbnail_url($document->ID, \'thumbnail\');?>" class="people-post-image"></a>
<a href="<?php echo get_permalink( $document->ID ); ?>" class="author-links">
<?php echo get_the_title( $document->ID ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
SO网友:Yash Tiwari
以下是获取帖子的更新代码,请检查是否有用:
$documents = get_posts(array(
\'post_type\' => \'post\',
\'posts_per_page\' => -1,
\'meta_query\' => array(
array(
\'key\' => \'our_people_author\', // name of custom field
\'value\' => \'"\' . get_the_ID() . \'"\', // matches exaclty "123", not just 123. This prevents a match for "1234"
\'compare\' => \'LIKE\'
)
)
));