Skip to content

Instantly share code, notes, and snippets.

@benfavre
Created March 22, 2018 15:31
Show Gist options
  • Save benfavre/9ea1ca9a7ff95499dc86289f1698fc4e to your computer and use it in GitHub Desktop.
Save benfavre/9ea1ca9a7ff95499dc86289f1698fc4e to your computer and use it in GitHub Desktop.
shortcode
<?php
function listingAvis ()
{
$taxonomy = array(
'fr' => 424,
'en' => 326
);
$taxId = $taxonomy[ pll_current_language () ];
ob_start ();
// WP_Query arguments
$args = array(
'post_type' => array('avis'),
'post_status' => array('publish'),
'posts_per_page' => '3'
);
// The Query
$find = new WP_Query($args);
// The Loop
if ($find->have_posts ()) {
?>
<ul class="avis-list"><?php
while ($find->have_posts ()) {
$find->the_post ();
$title = get_the_title ();
$title = str_insert ($title, 'corrective', PHP_EOL);
$title = str_insert ($title, 'évolutive', PHP_EOL);
?>
<li class="avis-item column-one">
<div class="icon">
<i class="mi mi-system-update"></i>
</div>
<a class="update-link" target="_blank"
href="<?php echo get_permalink (get_the_ID ()); ?>"><?php echo $title; ?></a>
</li>
<?php
}?>
</ul><?php
}
else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata ();
$output_string = ob_get_contents ();
ob_end_clean ();
return $output_string;
}
add_shortcode ('listing-avis', 'listingAvis');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment