admin管理员组文章数量:1317898
I created through ACF a relationship between blog posts and the custom post type, which contains employee profiles. Through the relationship, I am able to display links to the employee's profile, who is the author of a post.
I want to display now the list of posts created by employees at their profiles. I was able to find a code which does that. Unfortunately, whenever I assign more than 5 blog posts to an employee, the next ones are not visible. Would you be able to help me and tweak the code to display more than 5 posts in new rows?
<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>
I created through ACF a relationship between blog posts and the custom post type, which contains employee profiles. Through the relationship, I am able to display links to the employee's profile, who is the author of a post.
I want to display now the list of posts created by employees at their profiles. I was able to find a code which does that. Unfortunately, whenever I assign more than 5 blog posts to an employee, the next ones are not visible. Would you be able to help me and tweak the code to display more than 5 posts in new rows?
<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>
Share
Improve this question
asked Oct 23, 2020 at 6:37
AustralianreindeerAustralianreindeer
1
1 Answer
Reset to default 0Below is the updated code to fetch posts, please check is that helpful:
$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'
)
)
));
本文标签: phpWordpressdisplay relationship between blog posts and custom posts
版权声明:本文标题:php - Wordpress - display relationship between blog posts and custom posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742035445a2417263.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论