Generate festival calendar from database query
Clash 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(); ?>
performance php wordpress
add a comment |Â
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(); ?>
performance php wordpress
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
add a comment |Â
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(); ?>
performance php wordpress
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(); ?>
performance php wordpress
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
add a comment |Â
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
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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