Custom post slider output function
function custom_slider() {
$args = array(
'name' => 'homepage',
'post_type' => 'slider',
'posts_per_page' => 1
);
$posts = get_posts($args);
if ($posts) {
foreach ($posts as $post) {
setup_postdata($post);
if (have_rows('slider_images')) {
while (have_rows('slider_images')) {
the_row();
$img = get_sub_field('slider_image');
$link = get_sub_field('slider_link');
if (!empty($link)) {
echo sprintf('<a href="%s"><img src="%s" /></a>', $link, $img['url']);
} else {
echo sprintf('<img src="%s" />', $img['url']);
}
}
} else { echo "Could not find slider images."; }
}
wp_reset_postdata();
} else { echo "Could not find slider."; }
}