Skip to content

Instantly share code, notes, and snippets.

@philhoyt
Last active April 11, 2023 16:35
Show Gist options
  • Select an option

  • Save philhoyt/f54c1bb45fe843fd38bda0ed131b1cc3 to your computer and use it in GitHub Desktop.

Select an option

Save philhoyt/f54c1bb45fe843fd38bda0ed131b1cc3 to your computer and use it in GitHub Desktop.

Revisions

  1. philhoyt revised this gist Apr 11, 2023. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions lazy-related-posts.php
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,20 @@
    <?php
    $related_query = new WP_Query(array(
    'post_type' => 'post',
    'category__in' => wp_get_post_categories(get_the_ID()),
    'post__not_in' => array(get_the_ID()),
    $related_query = new WP_Query( array(
    'post_type' => get_post_type(),
    'category__in' => wp_get_post_categories( get_the_ID() ),
    'post__not_in' => array( get_the_ID() ),
    'posts_per_page' => 3,
    'orderby' => 'date',
    ));
    ) );
    ?>
    <?php if ($related_query->have_posts()): ?>

    <?php if ( $related_query->have_posts() ) : ?>
    <ul>
    <?php while ($related_query->have_posts()): ?>
    <?php $related_query->the_post(); ?>
    <?php while ( $related_query->have_posts() ) : $related_query->the_post(); ?>
    <li>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <a href='<?php the_permalink(); ?>'><?php the_title(); ?></a>
    </li>
    <?php endwhile; ?>
    </ul>
    <?php wp_reset_postdata(); ?>
    <?php endif; ?>
    <?php endif; ?>
  2. philhoyt created this gist Jul 2, 2021.
    20 changes: 20 additions & 0 deletions lazy-related-posts.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <?php
    $related_query = new WP_Query(array(
    'post_type' => 'post',
    'category__in' => wp_get_post_categories(get_the_ID()),
    'post__not_in' => array(get_the_ID()),
    'posts_per_page' => 3,
    'orderby' => 'date',
    ));
    ?>
    <?php if ($related_query->have_posts()): ?>
    <ul>
    <?php while ($related_query->have_posts()): ?>
    <?php $related_query->the_post(); ?>
    <li>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </li>
    <?php endwhile; ?>
    </ul>
    <?php wp_reset_postdata(); ?>
    <?php endif; ?>