I have created a post carousel within a WordPress page-template, but all other PHP (such as Advanced Custom Fields content and such) get blocked. The wp_debug shows no errors and I can't find any error within the code.
Below is the code I have used to create the carousel with recent posts from a custom post type:
When I entirely remove the slider all PHP below it does work/load, but I can't seem to find a mistake in the code.
<div class="carousel-inner" role="listbox">
<?php
$i = 2;
global $post;
$args = array(
'numberposts' => -1,
'post_type' => 'work',
'orderby' => 'date',
'order' => 'ASC',
);
$myposts = get_posts($args);
if($myposts):
$chunks = array_chunk($myposts, $i);
$html = "";
foreach($chunks as $chunk) {
($chunk === reset($chunks)) ? $active = "active" : $active = "";
$html .= '<div class="item '.$active.'">';
foreach($chunk as $post) {
$html .= '<div id="timeline-item" class="col-lg-6 col-md-6 col-sm-6 col-xs-6"><div><h6 style="text-align: left;">';
$html .= get_the_date('Y');
$html .= '</h6><h2 style="text-align: left;">';
$html .= get_the_title();
$html .= '</h2><p style="text-align: left;">';
$html .= get_post_field('post_content');
$html .= '</p></div></div>';
};
$html .= '</div>';
};
echo $html;
endif;
?>
</div>
You are overriding $post
. In WordPress never override $post
Try replacing this part.
foreach($chunk as $slide) {
$html .= '<div id="timeline-item" class="col-lg-6 col-md-6 col-sm-6 col-xs-6"><div><h6 style="text-align: left;">';
$html .= get_the_date('Y', $slide);
$html .= '</h6><h2 style="text-align: left;">';
$html .= get_the_title($slide);
$html .= '</h2><p style="text-align: left;">';
$html .= get_post_field('post_content', $slide);
$html .= '</p></div></div>';
};
Not sure if this will solve the rest of the problems. It might.
And if it doesn't at least your code will be a bit cleaner.
EDIT Seeing the full script this is very likely the problem.
line 109 if( have_rows('skill-bars')
will take the wrong $post
which you broke.