Forked from JacquesJahnichen/Search-events-nodates.php
Last active
March 22, 2017 12:12
-
-
Save jchristopher/941916c465f0e35c4376424ca38fb3df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: search-events-nodates | |
* | |
* This is template will display a login form | |
*/ | |
add_action('get_header', 'ck_do_login_form'); | |
// Début de page pour supprimer les commentaires présents sur les pages par défault | |
function ck_do_login_form() { | |
// Remove the comment form | |
add_filter('comments_open', '__return_false'); | |
// Remove the list of comments | |
add_filter('comments_array', '__return_empty_array'); | |
} | |
add_action( 'wp_enqueue_scripts', 'custom_load_custom_style_sheet' ); | |
function custom_load_custom_style_sheet() { | |
wp_enqueue_style( 'custom-stylesheet-grille', CHILD_URL . '/lib/vivi-search.css', array(), PARENT_THEME_VERSION ); | |
} | |
/* Template Name: Genesis and SearchWP integration with pagination */ | |
function prefix_searchwp_form( $query ) { | |
?> | |
<div class="search-form-workshops" > | |
<form class="searchwp-form-worksops" action=" " method="get"> | |
<input class="search-form-criteria" type="text" id="searchwpquery" name="searchwpquery" value="<?php echo esc_attr( $query ); ?>" /> | |
<select name="search-criteria-departement" class="search-form-criteria" > | |
<?php | |
$taxonomy = array('espresso_event_categories'); | |
$args = array('orderby'=>'name', 'hide_empty' => false, 'exclude' => array('71','81','297'), 'exclude_tree' => array('73','300'),); | |
$ee_terms = get_terms($taxonomy, $args); | |
foreach($ee_terms as $term){ | |
if (preg_match('/^[a-zA-Z]/', $term->name) == 1){ | |
$html_option = ""; | |
$html_option .= '<option class="' . $term->name . '" '; | |
foreach ($field_field_cities as $value) { | |
if ($value == $term->term_id) { | |
$html_option .= ' selected="selected" '; | |
} | |
} | |
$html_option .= ' >'. $term->name . '</option>'; | |
echo $html_option; | |
} | |
} | |
?> | |
</select> | |
<select class="search-form-criteria" name="search-criteria-categorie" id="ee_filter_cat" > | |
<option class="ee_filter_show_all" >Toute catégorie</option> | |
<!-- Get termes option : https://codex.wordpress.org/Function_Reference/get_terms --> | |
<?php | |
$taxonomy = array('espresso_event_categories'); | |
$args = array('orderby'=>'name','hide_empty'=>true, 'exclude' => array('73'), 'exclude_tree' => array('71','89'),); | |
$ee_terms = get_terms($taxonomy, $args); | |
foreach($ee_terms as $term){ | |
echo '<option class="' . $term->slug . '" >'. $term->name . '</option>'; | |
} | |
?> | |
</select> | |
<div class="search-form-more" style="display:none;"> | |
<select name="criteria_age" class="search-form-criteria" ></select> | |
<select name="criteria_niveau" class="search-form-criteria" ></select> | |
<select name="criteria_frequence" class="search-form-criteria" ></select> | |
</div> | |
<div class="search-form-submit" > | |
<button type="submit" ><?php echo __( 'Rechercher', 'text-domain' ); ?></button> | |
</div> | |
</form> | |
</div> | |
<?php | |
} | |
function mySearchEnginePostsPerPage() { | |
return 10; // 10 posts per page | |
} | |
function prefix_do_search_loop() { | |
global $wp_query, $post; | |
// Return early if SearchWP is disabled. | |
if ( ! class_exists( 'SearchWP' ) ) | |
return; | |
$searchwpquery = isset( $_GET['searchwpquery'] ) ? sanitize_text_field( $_GET['searchwpquery'] ) : ''; | |
$searchwppage = get_query_var( 'paged' ); | |
if( empty( $searchwppage ) ) | |
$searchwppage = 1; | |
// Load the custom SearchWP form. | |
prefix_searchwp_form( $searchwpquery ); | |
// Use WP_Query if no search was submitted | |
if ( empty( $searchwpquery ) ){ | |
$args = array( | |
'post_type' => 'UPDATE_ME', // needs to be Event Espresso post type name | |
'tax_query' => my_searchwp_get_tax_query() | |
); | |
$wp_query = new WP_Query( $args ); | |
$posts = $wp_query->posts; | |
} else { | |
// Instantiate SearchWP. | |
$engine = SearchWP::instance(); | |
// Set the supplemental search engine name. | |
$supplementalSearchEngineName = 'evenements'; | |
// perform the search | |
$posts = $engine->search( $supplementalSearchEngineName, $searchwpquery, $searchwppage ); | |
// prep pagiation | |
$original = array( 'max_num_pages' => $wp_query->max_num_pages, 'found_posts' => $wp_query->found_posts ); | |
$wp_query->max_num_pages = $engine->maxNumPages; | |
$wp_query->found_posts = $engine->foundPosts; | |
} | |
// trick subsequent function calls into thinking we're not on a page but in a loop | |
$wp_query-> is_singular = $wp_query->is_single = $wp_query->is_page = false; | |
// output our loop | |
if( !empty( $posts ) ) | |
{ | |
foreach ( $posts as $post ) | |
{ | |
setup_postdata( $post ); | |
html_event($post); | |
} | |
// this action already fires automatically if we're NOT on page 1, but only for prev/next | |
if( 'numeric' === genesis_get_option( 'posts_nav' ) || ( 'numeric' !== genesis_get_option( 'posts_nav' ) && $searchwppage < 2 ) ) | |
do_action( 'genesis_after_endwhile' ); | |
} else { | |
?> | |
<div style="height:400px;text-aligne:center;display:block;padding-top:30px;"> | |
<h3> Aucun résultat associé </h3> | |
</div> | |
<?php | |
} | |
$wp_query->max_num_pages = $original['max_num_pages']; | |
$wp_query->found_posts = $original['found_posts']; | |
} | |
/* | |
* All the people | |
*/ | |
function get_all_loop() { | |
/* | |
* All the people | |
*/ | |
$argsevents = array( | |
'post_type' => 'espresso_events', | |
'posts_per_page' => 10, | |
'orderby' => 'post_title', | |
'order' => 'ASC', | |
'paged' => $paged, | |
); | |
$wp_query = new WP_Query( $argsevents ); | |
if ( ! empty( $wp_query->posts ) ) { | |
foreach( $wp_query->posts as $post ) : setup_postdata( $post ); ?> | |
<div class="search-result"> | |
<?php html_event($post); ?> | |
</div> | |
<?php | |
endforeach; wp_reset_postdata(); | |
do_action( 'genesis_after_endwhile' ); | |
} else { | |
?><p>No results found.</p><?php | |
} | |
wp_reset_query(); */ | |
} | |
function html_event($post){ | |
global $post; | |
?> | |
<div class="event-presentation" > | |
<div class="event-img"> | |
<?php | |
echo '<a href="' . get_permalink() . '">'; | |
echo the_post_thumbnail('post-image'); //Add in featured image | |
echo '</a>'; | |
?> | |
</div> | |
<div class="event-text"> | |
<h2 id="post-<?php the_ID(); ?>" > | |
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> | |
<?php the_title(); ?></a> | |
</h2> | |
<div class="event-text-information" style="overflow:auto;"> | |
<?php echo do_shortcode( '[yasr_pro_average_comments_ratings size="small"]' ); ?><?php the_field( "tse_event_custom_level" )?>-<?php the_field( "tse_event_custom_age" )?> | |
</div> | |
<?php | |
echo the_excerpt(); | |
echo '<a href="' . get_permalink() . '" style="float:left;border:1px;">En savoir plus</a>'; | |
?> | |
</div> | |
<div class="event-button" > | |
<button>Consulter</button> | |
</div> | |
</div> | |
<?php | |
} | |
/* | |
* Filter - Get only old events | |
*/ | |
function my_searchwp_exclude_current( $ids, $engine, $terms ) { | |
if ( class_exists( 'EE_Registry' ) ) { | |
$exclude_query[0] = array( | |
'Datetime.DTT_EVT_end' => array( | |
'>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) | |
) | |
); | |
//first get all events that have datetimes where its not expired. | |
$exclude_event_ids = EE_Registry::instance()->load_model( 'Event' )->get_all_wpdb_results( $exclude_query, OBJECT_K, 'Event_CPT.ID' ); | |
$exclude_event_ids = array_keys( $exclude_event_ids ); | |
$ids = array_merge( $ids, $exclude_event_ids ); | |
$ids = array_unique( $ids ); | |
} | |
return $ids; | |
} | |
/* | |
* Filter - Add Taxonomy | |
*/ | |
function my_searchwp_get_tax_query() { | |
return array( | |
array( | |
'taxonomy' => 'people', | |
'field' => 'name', | |
'terms' => array( $_GET['search-criteria-departement'], $_GET['search-criteria-categorie'] ), | |
), | |
); | |
} | |
function my_searchwp_taxonomy_limiter( $ids ) { | |
// https://searchwp.com/docs/hooks/searchwp_include/ | |
if ( empty( $_GET['search-criteria-departement'] ) || empty( $_GET['search-criteria-categorie'] ) ) { | |
return $ids; | |
} | |
$args = array( | |
'post_type' => 'any', | |
'post_status' => 'any', | |
'nopaging' => true, | |
'fields' => 'ids', | |
'tax_query' => my_searchwp_get_tax_query() | |
); | |
$filtered_ids = get_posts( $args ); | |
$filtered_ids = array_map( 'absint', $filtered_ids ); | |
return array_unique( array_merge( $ids, $filtered_ids ) ); | |
} | |
function wsm_show_blog_page_title_text() { | |
echo '<center><h1 class="entry-title">' . get_the_title() . '</h1></center>'; | |
} | |
remove_action('genesis_loop', 'genesis_do_loop'); // Remove the standard loop | |
// Actions & Filters | |
//add_filter( 'searchwp_swp_query_args', 'my_searchwp_swp_query_args', 10, 3 ); | |
//remove_action('genesis_entry_content', 'genesis_do_post_content'); | |
//add_filter( 'searchwp_exclude', 'my_searchwp_exclude_current', 10, 3 ); | |
add_action( 'genesis_before_content', 'wsm_show_blog_page_title_text', 2 ); | |
add_filter( 'searchwp_posts_per_page', 'mySearchEnginePostsPerPage' ); | |
add_action('genesis_loop', 'prefix_do_search_loop'); // Add custom loop | |
// add_filter( 'searchwp_swp_query_args', 'my_searchwp_swp_query_args', 10, 3 ); | |
add_filter( 'searchwp_include', 'my_searchwp_taxonomy_limiter' ) | |
genesis(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment