A Simple WP_Query in a ShortCode/plugin
-
Hello Folks,
In a wordpress site i manage, i’m using an event query in many pages.
This query display a list of events (Im using event organiser).My user would like to display this list in some specific pages.
It’s is why i would like to create a Short Code, showing this event list in a post page.
I created a plugin, and a shortcode, but it wont work.
The Foreach part does not show.
Could you tell me a to use a WP query in a plugin/function properly ?Here is my query function (simplified).
<?php function wp_affiche_visites(){ ?> <?php $term_slug = "visites-guidees-et-gustatives-de-la-goutte-dor"; $events = new WP_Query(array( 'numberposts'=>-1, 'showpastevents'=>true,//Will be deprecated, but set it to true to play it safe. 'event-category'=>$term_slug )); if($events): return '<h1 class="page-title"> Visites guidées </h1>'; return '<div>'; foreach ($events as $event): return '<h3 style="margin:0; font-size:1em;"><a href="'.get_permalink($event->ID).'">'.get_the_title($event->ID).'</a></h3>'; endforeach; return '</div>'; endif; wp_reset_postdata(); } add_shortcode('affiche_visites', 'wp_affiche_visites'); ?>
The ShortCode [affiche_visites] just echoes “Visites guidées”.
Any ideas ?
Thanks you very much for any clues you could give me.
- The topic ‘A Simple WP_Query in a ShortCode/plugin’ is closed to new replies.