Support » Plugin: WordPress Infinite Scroll - Ajax Load More » My favorite plugin.

  • I used Ajax Load More to load related posts into my posts. It works just as designed, the documentation provided on the developers page is about as good as it gets. The support provided by the developer is nothing short of amazing. Definitely using this on every web site I build from now on.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here’s the code I use in Single.php to bring in posts by tags, or by categories if those tags are empty. Huge thanks to Darren for helping me troubleshoot it.

    
    // Related Posts by tag
    $terms = wp_get_post_tags($post->ID); // get current categories
    $term_array = []; // Create empty category array
    
    foreach( $terms as $term ) { // Loop founf categories
    $term_array[] = $term->slug;
    }
    $query = '';
    
    $args = array(
    'posts_per_page' 	=> 1,
    'post__not_in' 	=> $post->ID ,
    'tag' 				=> implode(",", $term_array),
    'post_type' 		=> 'post'
    );
    $related_posts = get_posts( $args );
    if ($related_posts) { // Tags
    
    $query = ' tag="'. implode(",", $term_array) .'"';
    
    } else {
    
    $categories = wp_get_post_categories($post->ID);
    
    if($categories){
    	$categories_array = [];
    	foreach ($categories as $category) {
    		$cat = get_term( $category );
    		$categories_array[] = $cat->slug;
    	}
    	if(!empty($categories_array)){
    		$query = ' category="'. implode(",", $categories_array) .'"';
    	}
    }
    
    }
    
    echo do_shortcode('[ajax_load_more'. $query .' post__not_in="' . $post->ID . '" post_type="post" posts_per_page="3" scroll="false" progress_bar="true" progress_bar_color="blue" images_loaded="true" button_label="Load More" css_classes="related-posts-container" button_loading_label="Loading More" container_type="div" ]');
    
    Plugin Author dcooney

    (@dcooney)

    Hi @turndriverside
    Thanks so much for the review and sharing your code!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this review.