I'm trying to add a custom post type custom loop in a widget.
Everything here worked correctly until I added the loop to the our_team_section_after()
function.
I can't find any syntax errors, however, Whenever I add the loop I get a 500 internal server error. When I take it back out, it works fine.
I'm using the Genesis Framework, so some of the hooks are genesis exclusive.
I've really been searching the web for an answer and I've returned no luck. Any help would be appreciated!
<?php
//Register the widget areas
genesis_register_sidebar( array(
'id' => 'landing-section',
'name' => __( 'Landing Section', 'genesis' ),
'description' => __( 'First Homepage Section.', 'Bootstrap Genesis' ),
) );
genesis_register_sidebar( array(
'id' => 'who-we-are-section',
'name' => __( 'Who We Are Section', 'genesis' ),
'description' => __( 'Who We Are Homepage Section.', 'Bootstrap Genesis' ),
) );
genesis_register_sidebar( array(
'id' => 'creative-process-section',
'name' => __( 'Creative Process Section', 'genesis' ),
'description' => __( 'Creative Process Homepage Section.', 'Bootstrap Genesis' ),
) );
genesis_register_sidebar( array(
'id' => 'services-section',
'name' => __( 'Services Section', 'genesis' ),
'description' => __( 'Services Homepage Section.', 'Bootstrap Genesis' ),
) );
genesis_register_sidebar( array(
'id' => 'our-team-section',
'name' => __( 'Our Team Section', 'genesis' ),
'description' => __( 'Our Team Homepage Section.', 'Bootstrap Genesis' ),
) );
genesis_register_sidebar( array(
'id' => 'case-studies-section',
'name' => __( 'Case Studies Section', 'genesis' ),
'description' => __( 'Case Studies Homepage Section.', 'Bootstrap Genesis' ),
) );
genesis_register_sidebar( array(
'id' => 'worked-with-section',
'name' => __( 'Who We\'ve Worked With', 'genesis' ),
'description' => __( 'Who We\'ve Worked With Homepage Section.', 'Bootstrap Genesis' ),
) );
//* Add the page widget in the content - XHTML
add_action( 'genesis_before_loop', 'front_page_content' );
function front_page_content() {
if ( is_front_page() ){
genesis_widget_area ('landing-section', array(
'before' => '<div id="landing-section"><div class="container">',
'after' => '</div></div>',
) );
genesis_widget_area ('who-we-are-section', array(
'before' => '<div id="who-we-are-section"><div class="container">',
'after' => '</div></div>',
) );
genesis_widget_area ('creative-process-section', array(
'before' => '<div id="creative-process-section"><div class="container">',
'after' => '</div></div>',
) );
genesis_widget_area ('services-section', array(
'before' => '<div id="services-section"><div class="container">',
'after' => '</div></div>',
) );
genesis_widget_area ('our-team-section', array(
'before' => our_team_section_before(),
'after' => our_team_section_after(),
) );
genesis_widget_area ('case-studies-section', array(
'before' => '<div id="case-studies-section"><div class="container">',
'after' => '</div></div>',
) );
genesis_widget_area ('worked-with-section', array(
'before' => '<div id="worked-with-section"><div class="container">',
'after' => '</div></div>',
) );
}
}
function our_team_section_before() {
$before = '<div id="our-team-section">';
$before .= '<div class="container">';
return $before;
}
function our_team_section_after() {
$after = '</div>';
$after .= '<div class="container-fluid">';
$after .= '<div class="row">';
$after .= '<div class="col-lg-9 col-sm-8 col-xs-12">';
$after .= '<div class="owl-carousel">';
$args = array(
'post_type' => 'team_post_type'
);
$query = new WP_Query($args);
if( $query -> have_posts() ){
$query -> while( have_posts() ){
$query -> the_post();
$after .= '<div>';
$after .= the_post_thumbnail();
$after .= '</div>';
}
wp_reset_postdata();
}
$after .= '</div>';
$after .= '</div>';
$after .= '<div class="col-lg-3 col-sm-4 col-xs-12">';
$after .= '<div class="homepage-cta">';
$after .= '<span>See Entire Team ></span>';
$after .= '</div>';
$after .= '</div>';
$after .= '</div>';
$after .= '</div>';
$after .= '</div>';
return $after;
}
the_post_thumbnail
in assignment (or any WP functions that start withthe_
), you need to useget_the_post_thumbnail
.$query -> while( have_posts() )
. Did you meanwhile($query->have_posts());
? Also you should move yourwp_reset_postdata()
out of the conditional.the_post_thumbnail()
will echo the content, while you need to return it. So as Milo mentioned, you should useget_the...
instead.