Generate festival calendar from database query

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












I'm building a calendar hour per hour for a five-day festival that has shows every 30 minutes and sometimes at the same time. I built this code that works correctly, but it's very slow to load on the page; approximatively 3000 lines of php and 100 queries to work!



How can I improve this code ?



 <?php
$time= "12:00:00";
$day= "20180705";
$args = array(
'numberposts' => -1,
'post_type' => 'spectacles',
'post_status' => 'any',
'meta_query' => array(
'relation' => 'AND',
array('key' => 'evenement_%_date_debut_evenement','compare' => '=','value' => $day),
array('key' => 'evenement_%_heure_debut_evenement','compare' => '=','value' => $time),
)
);?>

<?php $the_query = new WP_Query( $args );?>

<?php if( $the_query->have_posts() ): ?><?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php if (have_rows('evenement')) while (have_rows('evenement')) the_row();?>
<?php if (get_sub_field('heure_debut_evenement', false) == $time && get_sub_field('date_debut_evenement', false) == $day ) ?>
<div><?php echo $time ;?> > <?php the_sub_field('heure_fin_evenement'); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> • <?php if( get_field('compagnie') ): ?><?php the_field('compagnie'); ?> • <?php endif;?><?php $post_object = get_sub_field('lieu_evenement');if( $post_object ):?>
<?php $post = $post_object; setup_postdata( $post ); the_title();?>
<?php wp_reset_postdata();?><?php endif;?></div><?php ?>

<?php endwhile; ?><?php endif;?>
<?php wp_reset_query(); ?>

<!-- 12:30:00 -->

<?php
$time= "12:30:00";
$day= "20180705";
$args = array(
'numberposts' => -1,
'post_type' => 'spectacles',
'post_status' => 'any',
'meta_query' => array(
'relation' => 'AND',
array('key' => 'evenement_%_date_debut_evenement','compare' => '=','value' => $day),
array('key' => 'evenement_%_heure_debut_evenement','compare' => '=','value' => $time),
)
);?>

<?php $the_query = new WP_Query( $args );?>

<?php if( $the_query->have_posts() ): ?><?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php if (have_rows('evenement')) while (have_rows('evenement')) the_row();?>
<?php if (get_sub_field('heure_debut_evenement', false) == $time && get_sub_field('date_debut_evenement', false) == $day ) ?>
<div><?php echo $time ;?> > <?php the_sub_field('heure_fin_evenement'); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> • <?php if( get_field('compagnie') ): ?><?php the_field('compagnie'); ?> • <?php endif;?><?php $post_object = get_sub_field('lieu_evenement');if( $post_object ):?>
<?php $post = $post_object; setup_postdata( $post ); the_title();?>
<?php wp_reset_postdata();?><?php endif;?></div><?php ?>

<?php endwhile; ?><?php endif;?>
<?php wp_reset_query(); ?>






share|improve this question





















  • Cross posted from Stack Overflow.
    – Mathias Ettinger
    May 23 at 15:34






  • 1




    Welcome to Code Review! I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to give it a different title if there is something more appropriate.
    – Toby Speight
    May 23 at 15:43

















up vote
0
down vote

favorite












I'm building a calendar hour per hour for a five-day festival that has shows every 30 minutes and sometimes at the same time. I built this code that works correctly, but it's very slow to load on the page; approximatively 3000 lines of php and 100 queries to work!



How can I improve this code ?



 <?php
$time= "12:00:00";
$day= "20180705";
$args = array(
'numberposts' => -1,
'post_type' => 'spectacles',
'post_status' => 'any',
'meta_query' => array(
'relation' => 'AND',
array('key' => 'evenement_%_date_debut_evenement','compare' => '=','value' => $day),
array('key' => 'evenement_%_heure_debut_evenement','compare' => '=','value' => $time),
)
);?>

<?php $the_query = new WP_Query( $args );?>

<?php if( $the_query->have_posts() ): ?><?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php if (have_rows('evenement')) while (have_rows('evenement')) the_row();?>
<?php if (get_sub_field('heure_debut_evenement', false) == $time && get_sub_field('date_debut_evenement', false) == $day ) ?>
<div><?php echo $time ;?> > <?php the_sub_field('heure_fin_evenement'); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> • <?php if( get_field('compagnie') ): ?><?php the_field('compagnie'); ?> • <?php endif;?><?php $post_object = get_sub_field('lieu_evenement');if( $post_object ):?>
<?php $post = $post_object; setup_postdata( $post ); the_title();?>
<?php wp_reset_postdata();?><?php endif;?></div><?php ?>

<?php endwhile; ?><?php endif;?>
<?php wp_reset_query(); ?>

<!-- 12:30:00 -->

<?php
$time= "12:30:00";
$day= "20180705";
$args = array(
'numberposts' => -1,
'post_type' => 'spectacles',
'post_status' => 'any',
'meta_query' => array(
'relation' => 'AND',
array('key' => 'evenement_%_date_debut_evenement','compare' => '=','value' => $day),
array('key' => 'evenement_%_heure_debut_evenement','compare' => '=','value' => $time),
)
);?>

<?php $the_query = new WP_Query( $args );?>

<?php if( $the_query->have_posts() ): ?><?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php if (have_rows('evenement')) while (have_rows('evenement')) the_row();?>
<?php if (get_sub_field('heure_debut_evenement', false) == $time && get_sub_field('date_debut_evenement', false) == $day ) ?>
<div><?php echo $time ;?> > <?php the_sub_field('heure_fin_evenement'); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> • <?php if( get_field('compagnie') ): ?><?php the_field('compagnie'); ?> • <?php endif;?><?php $post_object = get_sub_field('lieu_evenement');if( $post_object ):?>
<?php $post = $post_object; setup_postdata( $post ); the_title();?>
<?php wp_reset_postdata();?><?php endif;?></div><?php ?>

<?php endwhile; ?><?php endif;?>
<?php wp_reset_query(); ?>






share|improve this question





















  • Cross posted from Stack Overflow.
    – Mathias Ettinger
    May 23 at 15:34






  • 1




    Welcome to Code Review! I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to give it a different title if there is something more appropriate.
    – Toby Speight
    May 23 at 15:43













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm building a calendar hour per hour for a five-day festival that has shows every 30 minutes and sometimes at the same time. I built this code that works correctly, but it's very slow to load on the page; approximatively 3000 lines of php and 100 queries to work!



How can I improve this code ?



 <?php
$time= "12:00:00";
$day= "20180705";
$args = array(
'numberposts' => -1,
'post_type' => 'spectacles',
'post_status' => 'any',
'meta_query' => array(
'relation' => 'AND',
array('key' => 'evenement_%_date_debut_evenement','compare' => '=','value' => $day),
array('key' => 'evenement_%_heure_debut_evenement','compare' => '=','value' => $time),
)
);?>

<?php $the_query = new WP_Query( $args );?>

<?php if( $the_query->have_posts() ): ?><?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php if (have_rows('evenement')) while (have_rows('evenement')) the_row();?>
<?php if (get_sub_field('heure_debut_evenement', false) == $time && get_sub_field('date_debut_evenement', false) == $day ) ?>
<div><?php echo $time ;?> > <?php the_sub_field('heure_fin_evenement'); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> • <?php if( get_field('compagnie') ): ?><?php the_field('compagnie'); ?> • <?php endif;?><?php $post_object = get_sub_field('lieu_evenement');if( $post_object ):?>
<?php $post = $post_object; setup_postdata( $post ); the_title();?>
<?php wp_reset_postdata();?><?php endif;?></div><?php ?>

<?php endwhile; ?><?php endif;?>
<?php wp_reset_query(); ?>

<!-- 12:30:00 -->

<?php
$time= "12:30:00";
$day= "20180705";
$args = array(
'numberposts' => -1,
'post_type' => 'spectacles',
'post_status' => 'any',
'meta_query' => array(
'relation' => 'AND',
array('key' => 'evenement_%_date_debut_evenement','compare' => '=','value' => $day),
array('key' => 'evenement_%_heure_debut_evenement','compare' => '=','value' => $time),
)
);?>

<?php $the_query = new WP_Query( $args );?>

<?php if( $the_query->have_posts() ): ?><?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php if (have_rows('evenement')) while (have_rows('evenement')) the_row();?>
<?php if (get_sub_field('heure_debut_evenement', false) == $time && get_sub_field('date_debut_evenement', false) == $day ) ?>
<div><?php echo $time ;?> > <?php the_sub_field('heure_fin_evenement'); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> • <?php if( get_field('compagnie') ): ?><?php the_field('compagnie'); ?> • <?php endif;?><?php $post_object = get_sub_field('lieu_evenement');if( $post_object ):?>
<?php $post = $post_object; setup_postdata( $post ); the_title();?>
<?php wp_reset_postdata();?><?php endif;?></div><?php ?>

<?php endwhile; ?><?php endif;?>
<?php wp_reset_query(); ?>






share|improve this question













I'm building a calendar hour per hour for a five-day festival that has shows every 30 minutes and sometimes at the same time. I built this code that works correctly, but it's very slow to load on the page; approximatively 3000 lines of php and 100 queries to work!



How can I improve this code ?



 <?php
$time= "12:00:00";
$day= "20180705";
$args = array(
'numberposts' => -1,
'post_type' => 'spectacles',
'post_status' => 'any',
'meta_query' => array(
'relation' => 'AND',
array('key' => 'evenement_%_date_debut_evenement','compare' => '=','value' => $day),
array('key' => 'evenement_%_heure_debut_evenement','compare' => '=','value' => $time),
)
);?>

<?php $the_query = new WP_Query( $args );?>

<?php if( $the_query->have_posts() ): ?><?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php if (have_rows('evenement')) while (have_rows('evenement')) the_row();?>
<?php if (get_sub_field('heure_debut_evenement', false) == $time && get_sub_field('date_debut_evenement', false) == $day ) ?>
<div><?php echo $time ;?> > <?php the_sub_field('heure_fin_evenement'); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> • <?php if( get_field('compagnie') ): ?><?php the_field('compagnie'); ?> • <?php endif;?><?php $post_object = get_sub_field('lieu_evenement');if( $post_object ):?>
<?php $post = $post_object; setup_postdata( $post ); the_title();?>
<?php wp_reset_postdata();?><?php endif;?></div><?php ?>

<?php endwhile; ?><?php endif;?>
<?php wp_reset_query(); ?>

<!-- 12:30:00 -->

<?php
$time= "12:30:00";
$day= "20180705";
$args = array(
'numberposts' => -1,
'post_type' => 'spectacles',
'post_status' => 'any',
'meta_query' => array(
'relation' => 'AND',
array('key' => 'evenement_%_date_debut_evenement','compare' => '=','value' => $day),
array('key' => 'evenement_%_heure_debut_evenement','compare' => '=','value' => $time),
)
);?>

<?php $the_query = new WP_Query( $args );?>

<?php if( $the_query->have_posts() ): ?><?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php if (have_rows('evenement')) while (have_rows('evenement')) the_row();?>
<?php if (get_sub_field('heure_debut_evenement', false) == $time && get_sub_field('date_debut_evenement', false) == $day ) ?>
<div><?php echo $time ;?> > <?php the_sub_field('heure_fin_evenement'); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> • <?php if( get_field('compagnie') ): ?><?php the_field('compagnie'); ?> • <?php endif;?><?php $post_object = get_sub_field('lieu_evenement');if( $post_object ):?>
<?php $post = $post_object; setup_postdata( $post ); the_title();?>
<?php wp_reset_postdata();?><?php endif;?></div><?php ?>

<?php endwhile; ?><?php endif;?>
<?php wp_reset_query(); ?>








share|improve this question












share|improve this question




share|improve this question








edited May 23 at 21:54









Sam Onela

5,75961543




5,75961543









asked May 23 at 15:24









Ben Belek

1




1











  • Cross posted from Stack Overflow.
    – Mathias Ettinger
    May 23 at 15:34






  • 1




    Welcome to Code Review! I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to give it a different title if there is something more appropriate.
    – Toby Speight
    May 23 at 15:43

















  • Cross posted from Stack Overflow.
    – Mathias Ettinger
    May 23 at 15:34






  • 1




    Welcome to Code Review! I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to give it a different title if there is something more appropriate.
    – Toby Speight
    May 23 at 15:43
















Cross posted from Stack Overflow.
– Mathias Ettinger
May 23 at 15:34




Cross posted from Stack Overflow.
– Mathias Ettinger
May 23 at 15:34




1




1




Welcome to Code Review! I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to give it a different title if there is something more appropriate.
– Toby Speight
May 23 at 15:43





Welcome to Code Review! I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to give it a different title if there is something more appropriate.
– Toby Speight
May 23 at 15:43
















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f195027%2fgenerate-festival-calendar-from-database-query%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f195027%2fgenerate-festival-calendar-from-database-query%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Greedy Best First Search implementation in Rust

Function to Return a JSON Like Objects Using VBA Collections and Arrays

C++11 CLH Lock Implementation