Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hawkidoki/97b9a90f151d29f327e59784e6c3f192 to your computer and use it in GitHub Desktop.
Save hawkidoki/97b9a90f151d29f327e59784e6c3f192 to your computer and use it in GitHub Desktop.
<?php
// Vérification que notre fichier est bien appelé via notre système
if(!$args = get_query_var('hwk_ajax_data'))
return;
// Data disponible:
// $args['id']
// $args['template']
// $args['cache']
// $args['flush']
// $args['param']
// $args['interval']
// Requête lourde ici
// Appel API, WP_Query etc...
$query = new WP_Query(array(
'post_type' => 'any',
'posts_per_page' => -1,
//'post__not_in' => array($args['param']), // On peut utiliser la valeur 'param' si celle-ci est définie.
));
?>
<!-- Obligatoire: Création du container avec les données pour traitement pour l'ajax Ajax -->
<!-- La fonction hwk_ajax_template_data() utilise $args['id'], $args['interval'] & $args['param'] -->
<div <?php hwk_ajax_template_data(); ?>>
<!-- Affichage HTML du résultat -->
<?php if($query->have_posts()): ?>
<?php while($query->have_posts()): $query->the_post(); ?>
<?php // ... ?>
<?php endwhile; wp_reset_query(); ?>
<?php endif(); ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment