Hi, that might probably be the case because the manual posts taps into the function. I think the solution might be rather simple and requires you to force the object/array. Assuming you’re using the below.
$posts = wp_list_pluck( (array) $scores, 'ID' );
Thread Starter
Li-An
(@li-an)
I’ve got this code:
global $post;
if(function_exists('get_crp_posts_id')){
$scores = get_crp_posts_id( array(
'postid' => $post->ID,
'limit' => 3,
'strict_limit' => TRUE,
) );
$posts = wp_list_pluck( $scores, 'ID' ); }
$args = array(
'post__in' => $posts ,
'showposts' => 3,
);
$ti_related_posts = new WP_Query( $args );
?>
<div class="single-box related-posts">
<h3 class="title"><?php _e( 'You may also like', 'themetext' ); ?></h3>
<div class="grids entries">
<div class="carousel">
<?php
if( $ti_related_posts->have_posts() ) :
while ( $ti_related_posts->have_posts() ) : $ti_related_posts->the_post(); ?>
<div class="item">
<figure class="entry-image">
<a href="<?php the_permalink(); ?>">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'rectangle-size-small' );
} ?>
</a>
</figure>
<header class="entry-header">
<h4>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
</h4>
</header>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
Please see this for the first part of the code:
https://gist.github.com/ajaydsouza/968b24a052e858bf8926#file-related-posts-php
It also works with the “Exclude this page” option in the meta box
Thread Starter
Li-An
(@li-an)
OK, thanks. I will study this.
global $post;
if ( function_exists('get_crp_posts_id' ) ) {
$scores = get_crp_posts_id( array(
'postid' => $post->ID,
'limit' => 3,
'strict_limit' => TRUE,
) );
$posts = wp_list_pluck( (array) $scores, 'ID' );
}
$args = array(
'post__in' => $posts,
'orderby' => 'post__in',
'showposts' => 3,
);
$ti_related_posts = new WP_Query( $args );
Thread Starter
Li-An
(@li-an)
It works ! Well done and great feature.
Thank you for confirming 🙂