Skip to content

Instantly share code, notes, and snippets.

@mennwebs
Created March 1, 2021 11:22
Show Gist options
  • Select an option

  • Save mennwebs/3c018690bf4fcb89ef7b55784f06dc9a to your computer and use it in GitHub Desktop.

Select an option

Save mennwebs/3c018690bf4fcb89ef7b55784f06dc9a to your computer and use it in GitHub Desktop.
Show related post from "Related Posts for WordPress By Never5" WordPress Plugin
<?php // Show related post from "Related Posts for WordPress By Never5" WordPress Plugin
$p_id = get_the_ID();
$link_args = array(
'post_type' => 'rp4wp_link',
'posts_per_page' => 6,
'meta_query' => array(
array(
'key' => 'rp4wp_parent',
'value' => $p_id,
'compare' => '=',
)
)
);
$wp_query = new WP_Query();
$posts = $wp_query->query( $link_args );
$child_ids = array();
foreach( $posts as $post ) {
$child_ids[] = get_post_meta( $post->ID, 'rp4wp_child', true );
}
$args = array(
'post__in' => $child_ids,
'orderby' => 'post__in',
'posts_per_page' => 6
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) {
$the_query->the_post();
get_template_part( 'template-parts/content', 'card' );
}
wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment