shortcode to show custom post types by category

I’m trying to create a list of my post types separated by custom category

ie

Tax
Cpt2
cpt3
Tax2
Cpt1
Cpt4
Tax3
Cpt5

I was hoping to do this through a shortcode, but keep getting an end of file error. I’m definitely missing something. Can Only run this code from an archive page?

Here is my code

function dhp_performersbycat() {
//start by fetching the terms for the performer_category taxonomy
$terms = get_terms( ‘performer_category’, array(
‘orderby’ => ‘count’,
‘hide_empty’ => 0
) );
$catlist = ”;
// now run a query for each term
foreach( $terms as $term ) {

// Define the query
$args = array(
‘post_type’ => ‘dhp_performers’,
‘performer_category’ => $term->slug
);
$query = new WP_Query( $args );

$catlist .= ‘<div class=”performercatlist”><h1>’ . $term->name . ‘</h1>’;

// Start the Loop
while ( $query->have_posts() ) : $query->the_post(); ?>

$catlist .= ‘<h2>’.the_title().'</h2>’;
$i++;
endwhile;

// use reset postdata to restore orginal query
wp_reset_postdata();
$catlist .= ‘</div>’;
}
return $catlist;
}

Read more here:: shortcode to show custom post types by category

Leave a Reply

Your email address will not be published. Required fields are marked *