Resource Topic Shortcode
// Add Shortcode
function resource_topic_shortcode( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'topic' => 'anti-corruption-anti-bribery',
'count' => '3',
),
$atts
);
$resource_topic = get_term_by( 'slug', $atts['topic'], 'resource-topic' );
$args = array(
"post_type" => array( "resources" ),
"post_status" => array( "publish" ),
"tax_query" => array(
array(
"taxonomy" => "resource-topic",
"field" => "slug",
"operator" => "IN",
"terms" => array( $atts['topic'] )
)
),
"posts_per_page" => $atts['count']
);
$resource_results = new WP_Query( $args );
ob_start();
if($resource_results->have_posts()):
echo '<div class="resources-results">';
while ( $resource_results->have_posts() ): $resource_results->the_post();
echo get_template_part( 'lib/template-parts/resource', 'listing' );
endwhile;
echo '</div>';
else:
echo '<p>Sorry, there are no resources that matched your search.</p>';
endif;
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode( 'resource_topic', 'resource_topic_shortcode' );