So, I have a function below to receive my messages, but I want the user to go directly to the page where the messages have the date “today”, which is not the date of publication of the event, but the date of the event when the event occurs, for example, if I have events with the man_date field man_date and today 2015-4-12 I will see directly the page on which this event does not accept these events on the first page.
function get_table(){ global $wpdb; $c_cid = $_REQUEST['cat']; if(isset($_REQUEST["page"])){ $page_number = filter_var($_REQUEST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); //filter number if(!is_numeric($page_number)){die('Invalid page number!');} //incase of invalid page number }else{ $page_number = 1; //if there no page number, set it to 1 } $item_per_page = 20; //get total number of records from database for pagination $get_total_row = $wpdb->get_results("SELECT wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE wp_term_taxonomy.taxonomy = 'tipo_manifestazione' AND wp_term_taxonomy.term_id = $c_cid AND wp_posts.post_status = 'publish' AND (wp_posts.vip = 'NULL' OR wp_posts.vip IS NULL) AND wp_posts.post_type = 'manifestazione' GROUP BY wp_posts.ID ORDER BY wp_posts.ID DESC"); $get_total_rows = count($get_total_row); //break records into pages $total_pages = ceil($get_total_rows/$item_per_page); //get starting position to fetch the records $page_position = (($page_number-1) * $item_per_page); ?> <section class="table_container"> <div class="controls_container"> <div class="control"> <select id="months" name="months"> <option value="" selected>Seleziona Mese</option> <option value="01">Gennaio</option> <option value="02">Febbraio</option> <option value="03">Marzo</option> <option value="04">Aprile</option> <option value="05">Maggio</option> <option value="06">Giugno</option> <option value="07">Luglio</option> <option value="08">Agosto</option> <option value="09">Settembre</option> <option value="10">Ottobre</option> <option value="11">Novembre</option> <option value="12">Dicembre</option> </select> </div> <div class="control"> <input type="text" name="location_search" id="location_search" placeholder="Luogo..."/> </div> <div class="control"> <div class="loading" style="display:none;"></div> </div> <div class="control right"> <?php echo paginate_function($item_per_page, $page_number, $get_total_rows, $total_pages); ?> </div> </div> <header class="table_header"> <div class="sec_th first"> <span class="sec_th_t">Voto</span> </div> <div class="sec_th second"> <span class="sec_th_t">Data</span> </div> <div class="sec_th third"> <span class="sec_th_t">Manifestazione</span> </div> <div class="sec_th fourth"> <span class="sec_th_t">Località</span> </div> <div class="sec_th fifth"> <span class="sec_th_t">Percorso Lungo</span> </div> <div class="sec_th sixth"> <span class="sec_th_t">Info</span> </div> </header> <div id="rows_container"> <?php $query = "SELECT wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE wp_term_taxonomy.taxonomy = 'tipo_manifestazione' AND wp_term_taxonomy.term_id = $c_cid AND wp_posts.post_status = 'publish' AND (wp_posts.vip = 'NULL' OR wp_posts.vip IS NULL) AND wp_posts.post_type = 'manifestazione' GROUP BY wp_posts.ID ORDER BY wp_posts.ID DESC LIMIT $page_position, $item_per_page"; $posts = $wpdb->get_results($query); foreach($posts as $post){ $permalink = get_permalink($post->ID); $locations = $wpdb->get_results("SELECT * FROM wp_locations WHERE post_id = $post->ID"); $l = $locations[0]; ?> <article id="row_<?php echo $post->ID;?>" class="table_row"> <div class="ar_td first"> <span class="ar_td_t"><?php echo do_shortcode('[ratings id="'.$post->ID.'"]');?></span> </div> <div class="ar_td second"> <span class="ar_td_t"><?php echo date("dmY", strtotime(get_field('m_f_data',$post->ID)));?></span> </div> <div class="ar_td third"> <a href="<?php echo $permalink;?>"><span class="ar_td_t"><?php echo $post->post_title;?></span></a> </div> <div class="ar_td fourth"> <a href="<?php echo site_url();?>/geo/?location=<?php echo $l->luogo;?>"> <span class="ar_td_t"><?php echo $l->luogo;?></span></a> </div> <div class="ar_td fifth"> <span class="ar_td_t"><?php echo get_field('m_f_percorso_lungo',$post->ID);?></span> </div> <div class="ar_td sixth"> <a href="javascript:void(0);" onclick="show_info('div_<?php echo $post->ID;?>','row_<?php echo $post->ID;?>');" class="show_button">Info +</a> </div> </article> <div id="div_<?php echo $post->ID;?>" class="div_content"> <?php get_post_fields($post->ID);?> </div> <?php } ?> </div> </section> <?php exit(); } function paginate_function($item_per_page, $current_page, $total_records, $total_pages) { $pagination = ''; if($total_pages > 0 && $total_pages != 1 && $current_page <= $total_pages){ "SELECT wp_posts. * FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE wp_term_taxonomy.taxonomy = 'tipo_manifestazione' function get_table(){ global $wpdb; $c_cid = $_REQUEST['cat']; if(isset($_REQUEST["page"])){ $page_number = filter_var($_REQUEST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); //filter number if(!is_numeric($page_number)){die('Invalid page number!');} //incase of invalid page number }else{ $page_number = 1; //if there no page number, set it to 1 } $item_per_page = 20; //get total number of records from database for pagination $get_total_row = $wpdb->get_results("SELECT wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE wp_term_taxonomy.taxonomy = 'tipo_manifestazione' AND wp_term_taxonomy.term_id = $c_cid AND wp_posts.post_status = 'publish' AND (wp_posts.vip = 'NULL' OR wp_posts.vip IS NULL) AND wp_posts.post_type = 'manifestazione' GROUP BY wp_posts.ID ORDER BY wp_posts.ID DESC"); $get_total_rows = count($get_total_row); //break records into pages $total_pages = ceil($get_total_rows/$item_per_page); //get starting position to fetch the records $page_position = (($page_number-1) * $item_per_page); ?> <section class="table_container"> <div class="controls_container"> <div class="control"> <select id="months" name="months"> <option value="" selected>Seleziona Mese</option> <option value="01">Gennaio</option> <option value="02">Febbraio</option> <option value="03">Marzo</option> <option value="04">Aprile</option> <option value="05">Maggio</option> <option value="06">Giugno</option> <option value="07">Luglio</option> <option value="08">Agosto</option> <option value="09">Settembre</option> <option value="10">Ottobre</option> <option value="11">Novembre</option> <option value="12">Dicembre</option> </select> </div> <div class="control"> <input type="text" name="location_search" id="location_search" placeholder="Luogo..."/> </div> <div class="control"> <div class="loading" style="display:none;"></div> </div> <div class="control right"> <?php echo paginate_function($item_per_page, $page_number, $get_total_rows, $total_pages); ?> </div> </div> <header class="table_header"> <div class="sec_th first"> <span class="sec_th_t">Voto</span> </div> <div class="sec_th second"> <span class="sec_th_t">Data</span> </div> <div class="sec_th third"> <span class="sec_th_t">Manifestazione</span> </div> <div class="sec_th fourth"> <span class="sec_th_t">Località</span> </div> <div class="sec_th fifth"> <span class="sec_th_t">Percorso Lungo</span> </div> <div class="sec_th sixth"> <span class="sec_th_t">Info</span> </div> </header> <div id="rows_container"> <?php $query = "SELECT wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE wp_term_taxonomy.taxonomy = 'tipo_manifestazione' AND wp_term_taxonomy.term_id = $c_cid AND wp_posts.post_status = 'publish' AND (wp_posts.vip = 'NULL' OR wp_posts.vip IS NULL) AND wp_posts.post_type = 'manifestazione' GROUP BY wp_posts.ID ORDER BY wp_posts.ID DESC LIMIT $page_position, $item_per_page"; $posts = $wpdb->get_results($query); foreach($posts as $post){ $permalink = get_permalink($post->ID); $locations = $wpdb->get_results("SELECT * FROM wp_locations WHERE post_id = $post->ID"); $l = $locations[0]; ?> <article id="row_<?php echo $post->ID;?>" class="table_row"> <div class="ar_td first"> <span class="ar_td_t"><?php echo do_shortcode('[ratings id="'.$post->ID.'"]');?></span> </div> <div class="ar_td second"> <span class="ar_td_t"><?php echo date("dmY", strtotime(get_field('m_f_data',$post->ID)));?></span> </div> <div class="ar_td third"> <a href="<?php echo $permalink;?>"><span class="ar_td_t"><?php echo $post->post_title;?></span></a> </div> <div class="ar_td fourth"> <a href="<?php echo site_url();?>/geo/?location=<?php echo $l->luogo;?>"> <span class="ar_td_t"><?php echo $l->luogo;?></span></a> </div> <div class="ar_td fifth"> <span class="ar_td_t"><?php echo get_field('m_f_percorso_lungo',$post->ID);?></span> </div> <div class="ar_td sixth"> <a href="javascript:void(0);" onclick="show_info('div_<?php echo $post->ID;?>','row_<?php echo $post->ID;?>');" class="show_button">Info +</a> </div> </article> <div id="div_<?php echo $post->ID;?>" class="div_content"> <?php get_post_fields($post->ID);?> </div> <?php } ?> </div> </section> <?php exit(); } function paginate_function($item_per_page, $current_page, $total_records, $total_pages) { $pagination = ''; if($total_pages > 0 && $total_pages != 1 && $current_page <= $total_pages){ FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE wp_term_taxonomy.taxonomy = 'tipo_manifestazione' AND wp_term_taxonomy.term_id = $ function get_table(){ global $wpdb; $c_cid = $_REQUEST['cat']; if(isset($_REQUEST["page"])){ $page_number = filter_var($_REQUEST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); //filter number if(!is_numeric($page_number)){die('Invalid page number!');} //incase of invalid page number }else{ $page_number = 1; //if there no page number, set it to 1 } $item_per_page = 20; //get total number of records from database for pagination $get_total_row = $wpdb->get_results("SELECT wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE wp_term_taxonomy.taxonomy = 'tipo_manifestazione' AND wp_term_taxonomy.term_id = $c_cid AND wp_posts.post_status = 'publish' AND (wp_posts.vip = 'NULL' OR wp_posts.vip IS NULL) AND wp_posts.post_type = 'manifestazione' GROUP BY wp_posts.ID ORDER BY wp_posts.ID DESC"); $get_total_rows = count($get_total_row); //break records into pages $total_pages = ceil($get_total_rows/$item_per_page); //get starting position to fetch the records $page_position = (($page_number-1) * $item_per_page); ?> <section class="table_container"> <div class="controls_container"> <div class="control"> <select id="months" name="months"> <option value="" selected>Seleziona Mese</option> <option value="01">Gennaio</option> <option value="02">Febbraio</option> <option value="03">Marzo</option> <option value="04">Aprile</option> <option value="05">Maggio</option> <option value="06">Giugno</option> <option value="07">Luglio</option> <option value="08">Agosto</option> <option value="09">Settembre</option> <option value="10">Ottobre</option> <option value="11">Novembre</option> <option value="12">Dicembre</option> </select> </div> <div class="control"> <input type="text" name="location_search" id="location_search" placeholder="Luogo..."/> </div> <div class="control"> <div class="loading" style="display:none;"></div> </div> <div class="control right"> <?php echo paginate_function($item_per_page, $page_number, $get_total_rows, $total_pages); ?> </div> </div> <header class="table_header"> <div class="sec_th first"> <span class="sec_th_t">Voto</span> </div> <div class="sec_th second"> <span class="sec_th_t">Data</span> </div> <div class="sec_th third"> <span class="sec_th_t">Manifestazione</span> </div> <div class="sec_th fourth"> <span class="sec_th_t">Località</span> </div> <div class="sec_th fifth"> <span class="sec_th_t">Percorso Lungo</span> </div> <div class="sec_th sixth"> <span class="sec_th_t">Info</span> </div> </header> <div id="rows_container"> <?php $query = "SELECT wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE wp_term_taxonomy.taxonomy = 'tipo_manifestazione' AND wp_term_taxonomy.term_id = $c_cid AND wp_posts.post_status = 'publish' AND (wp_posts.vip = 'NULL' OR wp_posts.vip IS NULL) AND wp_posts.post_type = 'manifestazione' GROUP BY wp_posts.ID ORDER BY wp_posts.ID DESC LIMIT $page_position, $item_per_page"; $posts = $wpdb->get_results($query); foreach($posts as $post){ $permalink = get_permalink($post->ID); $locations = $wpdb->get_results("SELECT * FROM wp_locations WHERE post_id = $post->ID"); $l = $locations[0]; ?> <article id="row_<?php echo $post->ID;?>" class="table_row"> <div class="ar_td first"> <span class="ar_td_t"><?php echo do_shortcode('[ratings id="'.$post->ID.'"]');?></span> </div> <div class="ar_td second"> <span class="ar_td_t"><?php echo date("dmY", strtotime(get_field('m_f_data',$post->ID)));?></span> </div> <div class="ar_td third"> <a href="<?php echo $permalink;?>"><span class="ar_td_t"><?php echo $post->post_title;?></span></a> </div> <div class="ar_td fourth"> <a href="<?php echo site_url();?>/geo/?location=<?php echo $l->luogo;?>"> <span class="ar_td_t"><?php echo $l->luogo;?></span></a> </div> <div class="ar_td fifth"> <span class="ar_td_t"><?php echo get_field('m_f_percorso_lungo',$post->ID);?></span> </div> <div class="ar_td sixth"> <a href="javascript:void(0);" onclick="show_info('div_<?php echo $post->ID;?>','row_<?php echo $post->ID;?>');" class="show_button">Info +</a> </div> </article> <div id="div_<?php echo $post->ID;?>" class="div_content"> <?php get_post_fields($post->ID);?> </div> <?php } ?> </div> </section> <?php exit(); } function paginate_function($item_per_page, $current_page, $total_records, $total_pages) { $pagination = ''; if($total_pages > 0 && $total_pages != 1 && $current_page <= $total_pages){
Ajax:
jQuery("#get_table").load(ajaxurl,{'action':'get_table','cat':cat,'page':page});
The code works well to receive messages, and pagination works well, the only thing I can’t understand, since I can make this thing use directly on the page where the messages are with the current matching date.