• Resolved Li-An

    (@li-an)


    Hello,
    I just tried this new cool function – adding manually a related post – and… it completely breaks my theme ! Sidebar disepearded, author box became mad.

    I cleaned the field and everything went smooth again. As I used a custom function to insert related posts to adapt to my theme as you explained me, may I have to change it ?

    https://ww.wp.xz.cn/plugins/contextual-related-posts/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author WebberZone

    (@webberzone)

    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; ?>
    Plugin Author WebberZone

    (@webberzone)

    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.

    Plugin Author WebberZone

    (@webberzone)

    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.

    Plugin Author WebberZone

    (@webberzone)

    Thank you for confirming 🙂

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Problem with manual adding related post’ is closed to new replies.