Why is my custom post type slider only displaying the latest slide?
after a search throughout the already asked questions I couldn’t come to a solution to my problem, this one is the closest I found: My custom post type displays the [latest post]
I had a slider built into the homepage, but I have noticed that after a while of it working fine, it now only displays the latest post type.
Here is the current code for the slider:
<div class="half slide-container">
<ul class="slider">
<?php
$slides = get_posts( array(
'numberposts' => 6,
'post_type' => 'slides',
'orderby' => 'post_date'
) );
foreach( $slides as $post ) :
setup_postdata( $post );
$args = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'orderby' => 'post_date',
'order' => 'ASC',
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
?>
<li data-background="http://www.serps.co.uk/cdn/PG/background14.png">
<?php the_content( ); ?>
</li>
<?php endforeach; ?>
</ul>
</div>
I’m relatively new to .php, but I thought I had spotted a couple of syntax errors but the slider still remained broken.
I changed it to this to no avail:
<div class="half slide-container">
<ul class="slider">
<?php
$slides = get_posts( array(
'numberposts' => '3',
'post_type' => 'slides',
'orderby' => 'post_date'
) );
foreach( $slides as $post ) :
setup_postdata( $post );
$args = array(
'post_type' => 'attachment',
'numberposts' => '3',
'post_status' => 'publish',
'orderby' => 'post_date',
'order' => 'ASC',
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
?>
<li data-background="http://www.serps.co.uk/cdn/PG/background14.png">
<?php the_content( ); ?>
</li>
<?php endforeach; ?>
</ul>
</div>
You can view this live on the website here: Polesworth Garage
Leave an answer