All Advertisemetns
// WP_Query arguments
$args = array(
'name' => 'ad',
'post_type' => array( 'ad' ),
'post_status' => array( 'publish' ),
'has_password' => false,
'nopaging' => false,
'posts_per_page' => '20',
'posts_per_archive_page' => '20',
'ignore_sticky_posts' => false,
'order' => 'DESC',
'orderby' => 'date',
);
// The Query
$query_all_advertisements = new WP_Query( $args );
// The Loop
if ( $query_all_advertisements->have_posts() ) {
while ( $query_all_advertisements->have_posts() ) {
$query_all_advertisements->the_post();
// do something
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();