Skip to content

Instantly share code, notes, and snippets.

@muks999
Forked from artikus11/shortcode.php
Created October 9, 2018 12:57
Show Gist options
  • Save muks999/13f3f0809ae4496f191b3d85fe67a778 to your computer and use it in GitHub Desktop.
Save muks999/13f3f0809ae4496f191b3d85fe67a778 to your computer and use it in GitHub Desktop.
Шорткод вывода постов по ID
add_shortcode( 'art_related_posts', 'related_posts_function' );
function related_posts_function ($atts){
$atts = shortcode_atts( array(
'id' => '',
'count' => 3
), $atts );
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $atts['count'],
'include' => $atts['id']
);
$out_posts = get_posts( $args );
$out = '<style>
.art-rp{
background: #ddd;
padding: 20px 20px;
}
</style>';
$out .= '<ul class="art-rp">';
foreach ($out_posts as $post) {
setup_postdata( $post );
$out .= '<li><a href="'. get_the_permalink($post->ID) .'">'. get_the_title( $post->ID ) . '</a></li>';
}
$out .= '</ul>';
wp_reset_postdata();
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment