here is a working example, add this code to your functions.php file:
function wa426_latest_ads($atts) {
$args = array('post_type' => 'advert',
'orderby' => 'date',
'posts_per_page' => $atts['count'],
'order' => 'DESC');
$wa_query = new WP_Query($args);
// The Loop
if ($wa_query->have_posts()) {
echo '<ul>';
while ($wa_query->have_posts()) {
$wa_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
}
add_shortcode('wa426_latest_ads', 'wa426_latest_ads');
then, call the shortcode wherever you need it:
[wa426_latest_ads count="3"]
where count is the number of ads you want to show.
for the related ads, you can make a custom single.php for the ads and add the query wherever you need it in that single page (under the post for example), don’t forget to add the 'advert-category' => $actual_post_cat
to this last query so it will only get latest ads of the same category.
you can get $actual_post_cat with :
$actual_post_cat = get_the_terms ( $post, 'advert-category' );
in case you don’t know how or where to make the single file, you need to make a copy of your theme’s single.php and call it single-advert.php