Commit a63dcfa0 authored by Simonas's avatar Simonas

City & Categories ordering, optimization

parent 781f20f5
...@@ -91,8 +91,8 @@ ...@@ -91,8 +91,8 @@
<script src="/wp-content/themes/biuro/js/main.min.js" async></script> <script src="/wp-content/themes/biuro/js/main.min.js" async></script>
<?php <?php
global $time_start; // global $time_start;
delog((microtime(true) - $time_start), 'Lorem ipsum'); // delog((microtime(true) - $time_start), 'Lorem ipsum');
?> ?>
<?php wp_footer(); ?> <?php wp_footer(); ?>
</body> </body>
......
This diff is collapsed.
<?php <?php
global $time_start; // global $time_start;
$time_start = microtime(true); // $time_start = microtime(true);
// getRecords('city');
// getRecords('field');
// getRecords('type');
?><!DOCTYPE html> ?><!DOCTYPE html>
<html <?php language_attributes(); ?>> <html <?php language_attributes(); ?>>
<head> <head>
......
...@@ -49,52 +49,18 @@ get_header(); ?> ...@@ -49,52 +49,18 @@ get_header(); ?>
<div class="c-divisions"> <div class="c-divisions">
<?php <?php
if ( 1 < $divisions->total() ): if ( 1 < $divisions->total() ):
/*
$divisionsPage = new WP_Query( array(
'numberposts' => 1,
'post_type' => 'page',
'meta_key' => 'page',
'meta_value' => 'employees-contacts'
) );
if ( $divisionsPage->have_posts() ) :
while( $divisionsPage->have_posts() ) :
$divisionsPage->the_post();
?>
<a class="c-division <?php if ( $total == 0 ) { echo 'c-division--active'; } ?>" href="<?php the_permalink(); ?>"><?php _e('All', 'biuro'); ?></a>
<?php
endwhile;
else:
*/
?> ?>
<span class="js-division c-division"><?php _e('All', 'biuro'); ?></span> <span class="js-division c-division"><?php _e('All', 'biuro'); ?></span>
<?php <?php
/*
endif;
*/
wp_reset_query();
endif; endif;
while ( $divisions->fetch() ) : while ( $divisions->fetch() ) :
$slug = $divisions->display( 'city.slug' ); $slug = $divisions->display( 'city.slug' );
if ( !in_array($slug, $cities) && $divisions->display( 'name' ) ) : if ( !in_array($slug, $cities) && $divisions->display( 'name' ) ) :
/*
$page = $divisions->field( 'page-id' );
if ( !empty( $page ) ):
?>
<a class="js-division c-division <?php if ( $pageID == $page['ID'] ) { echo 'c-division--active'; } ?>" data-id="<?php echo $slug; ?>" href="<?php echo esc_url( get_permalink( $page['ID'] ) ); ?>"><?php echo $divisions->display( 'city' ); ?></a>
<?php
else:
*/
?> ?>
<span class="js-division c-division" data-id="<?php echo $slug; ?>"><?php echo $divisions->display( 'city' ); ?></span> <span class="js-division c-division" data-id="<?php echo $slug; ?>"><?php echo $divisions->display( 'city' ); ?></span>
<?php <?php
/*
endif;
*/
array_push($cities, $slug); array_push($cities, $slug);
endif; endif;
endwhile; endwhile;
......
...@@ -125,7 +125,7 @@ get_header(); ?> ...@@ -125,7 +125,7 @@ get_header(); ?>
continue; continue;
endif; endif;
$res = get_post_custom_values( $val, $ID ); $res = get_post_custom_values( $val );
if ( !$res ) : if ( !$res ) :
continue; continue;
......
...@@ -74,7 +74,6 @@ get_header(); ?> ...@@ -74,7 +74,6 @@ get_header(); ?>
<?php <?php
global $query_string; global $query_string;
$ID = get_the_ID();
$keys = get_post_custom_keys(); $keys = get_post_custom_keys();
$where = 'valid.meta_value > "' . date('Y-m-d', strtotime('-1 days')) . '"'; $where = 'valid.meta_value > "' . date('Y-m-d', strtotime('-1 days')) . '"';
...@@ -120,7 +119,7 @@ get_header(); ?> ...@@ -120,7 +119,7 @@ get_header(); ?>
continue; continue;
endif; endif;
$res = get_post_custom_values( $val, $ID ); $res = get_post_custom_values( $val );
if ( !$res ) : if ( !$res ) :
continue; continue;
......
...@@ -28,12 +28,6 @@ if ( get_post_type() == 'page' ): ...@@ -28,12 +28,6 @@ if ( get_post_type() == 'page' ):
endif; endif;
?>
<?php
// $res = getRecords('city', $searchQuery);
// debug($res);
// exit();
?> ?>
<form id="search" class="c-search" action="<?php echo home_url(); ?>" method="get"> <form id="search" class="c-search" action="<?php echo home_url(); ?>" method="get">
...@@ -43,16 +37,14 @@ endif; ...@@ -43,16 +37,14 @@ endif;
</svg> </svg>
<datalist id="search-cities"> <datalist id="search-cities">
<?php <?php
$res = getRecords('city', $searchQuery); foreach ( getOptions('city') as $r ):
foreach ( $res as $r ):
?> ?>
<option value="<?php echo $r['name']; ?>"><?php echo $r['name']; ?> (<?php echo $r['total']; ?>)</option> <option value="<?php echo $r['name']; ?>"><?php echo $r['name']; ?> (<?php echo $r['total']; ?>)</option>
<?php <?php
endforeach; endforeach;
?> ?>
</datalist> </datalist>
<input list="search-cities" id="search-city" name="city" value="<?php echo ($searchQuery && $searchQuery['city']) ? trim(urldecode($searchQuery['city'])) : ''; ?>" placeholder="<?php _e('Locations', 'biuro'); ?>" class="c-search--input c-search--location" /> <input list="search-cities" id="search-city" name="city" value="<?php echo (isset($searchQuery['city'])) ? trim(urldecode($searchQuery['city'])) : ''; ?>" placeholder="<?php _e('Locations', 'biuro'); ?>" class="c-search--input c-search--location" />
</div><!-- .c-search--col c-search--col-location --> </div><!-- .c-search--col c-search--col-location -->
<div class="c-search--col c-search--col-keyword"> <div class="c-search--col c-search--col-keyword">
...@@ -62,15 +54,14 @@ endif; ...@@ -62,15 +54,14 @@ endif;
<datalist id="search-queries"> <datalist id="search-queries">
<?php <?php
$options = array_merge(getRecords('field', $searchQuery), getRecords('type', $searchQuery)); foreach ( array_merge(getOptions('field'), getOptions('type')) as $option ):
foreach ( $options as $option ):
?> ?>
<option value="<?php echo $option['name']; ?>"><?php echo $option['name']; ?> (<?php echo $option['total']; ?>)</option> <option value="<?php echo $option['name']; ?>"><?php echo $option['name']; ?> (<?php echo $option['total']; ?>)</option>
<?php <?php
endforeach; endforeach;
?> ?>
</datalist> </datalist>
<input list="search-queries" id="search-query" name="s" value="<?php echo ($searchQuery && $searchQuery['s']) ? trim(urldecode($searchQuery['s'])) : ''; ?>" placeholder="<?php _e('Keyword', 'biuro'); ?>" class="c-search--input c-search--keyword" /> <input list="search-queries" id="search-query" name="s" value="<?php echo (isset($searchQuery['s'])) ? trim(urldecode($searchQuery['s'])) : ''; ?>" placeholder="<?php _e('Keyword', 'biuro'); ?>" class="c-search--input c-search--keyword" />
</div><!-- .c-search--col c-search--col-keyword --> </div><!-- .c-search--col c-search--col-keyword -->
<button class="o-btn c-btn--main <?php if ( is_front_page() ): ?>c-btn--search<?php else: ?>c-btn--search-small<?php endif; ?>" type="submit" value="1"> <button class="o-btn c-btn--main <?php if ( is_front_page() ): ?>c-btn--search<?php else: ?>c-btn--search-small<?php endif; ?>" type="submit" value="1">
<svg xmlns="http://www.w3.org/2000/svg" width="17px" height="17px" viewBox="0 0 17 17" class="c-ico--search"> <svg xmlns="http://www.w3.org/2000/svg" width="17px" height="17px" viewBox="0 0 17 17" class="c-ico--search">
......
...@@ -17,6 +17,7 @@ global $jobs; ...@@ -17,6 +17,7 @@ global $jobs;
$i = 0; $i = 0;
while ( $jobs->fetch() ) : while ( $jobs->fetch() ) :
$ID = $jobs->display( 'ID' ); $ID = $jobs->display( 'ID' );
$name = $jobs->display( 'name' );
//Primary city id //Primary city id
$primaryCities = get_post_meta($ID, '_yoast_wpseo_primary_city'); $primaryCities = get_post_meta($ID, '_yoast_wpseo_primary_city');
...@@ -25,7 +26,7 @@ global $jobs; ...@@ -25,7 +26,7 @@ global $jobs;
?> ?>
<tr <?php if ( $i % 2 != 0 ) { echo 'class="c-jobs--row-odd"'; } ?>> <tr <?php if ( $i % 2 != 0 ) { echo 'class="c-jobs--row-odd"'; } ?>>
<td class="c-jobs--col c-jobs--col-position"> <td class="c-jobs--col c-jobs--col-position">
<a class="c-jobs--anchor" href="<?php echo get_post_permalink( $ID ); ?>" title="<?php echo $jobs->display( 'name' ); ?>"><?php echo $jobs->display( 'name' ); ?></a> <a class="c-jobs--anchor" href="<?php echo get_post_permalink( $ID ); ?>" title="<?php echo $name; ?>"><?php echo $name; ?></a>
</td> </td>
<td class="c-jobs--col c-jobs--col-city"> <td class="c-jobs--col c-jobs--col-city">
<?php <?php
......
...@@ -16,157 +16,14 @@ function getPageURL($taxonomy, $pageURL, $searchQuery, $termID) { ...@@ -16,157 +16,14 @@ function getPageURL($taxonomy, $pageURL, $searchQuery, $termID) {
return $pageURL; return $pageURL;
} }
function getSiteTree2($taxonomy, $section, $searchQuery) {
$terms = get_terms( array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
));
if ( !empty( $terms ) && ! is_wp_error( $terms ) ):
$res = array();
if ($searchQuery['city']):
$city = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['city']), 'city' );
endif;
if ($searchQuery['s']):
$field = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'field' );
$type = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'type' );
endif;
foreach ( $terms as $term ):
$termID = $term->term_id;
$active = false;
$where = 'valid.meta_value > "' . date('Y-m-d', strtotime('-1 days')) . '" AND ' . $taxonomy . '.term_id = ' . $termID;
$counter = $where;
if ($taxonomy == 'city'):
if ( $field ) :
$counter = $counter . ' AND field.term_id = ' . $field->term_id;
elseif ( $type ) :
$counter = $counter . ' AND type.term_id = ' . $type->term_id;
else:
$counter = $counter . ' AND (t.post_title LIKE "%' . $searchQuery['s'] . '%" OR t.post_content LIKE "%' . $searchQuery['s'] . '%")';
endif;
if ( $city && $city->term_id == $termID ) :
$active = true;
endif;
elseif ($taxonomy == 'type' || $taxonomy == 'field'):
if ( $city ) :
$counter = $counter . ' AND city.term_id = ' . $city->term_id;
endif;
if ( $field && $field->term_id == $termID || $type && $type->term_id == $termID) :
$active = true;
endif;
endif;
$params = array(
'where' => $where,
'limit' => -1
);
$jobsIn = pods( 'job', $params );
$custom = array(
'where' => $counter,
'limit' => -1
);
$jobsCounter = pods( 'job', $custom );
// global $wpdb;
// if ($taxonomy == 'field') {
// delog($wpdb->last_query, 'last_query');
// debug($wpdb->last_result);
// }
if ( 0 < $jobsIn->total() ):
$page = get_term_meta( $termID, 'page-id', true);
$order = intval(get_term_meta( $termID, 'order', true));
if ( $page && $page['post_status'] === 'publish') :
array_push($res, array(
'name' => $page['post_title'],
'href' => getPageURL($taxonomy, get_page_link( $page['ID'] ), $searchQuery, $termID),
'order' => $order,
'total' => $jobsCounter->total(),
'active' => $active
));
endif;
endif;
endforeach;
if (count($res) == 0) {
return '';
}
usort($res, function($a, $b) {
$o = $b['order'] - $a['order'];
if ($o):
return $o;
endif;
$t = $b['total'] - $a['total'];
if ($t):
return $t;
endif;
return $a['name'] > $b['name'];
});
$classCSS = 'c-jobs-section';
$isClosed = count($res) > 3;
if ($isClosed):
$classCSS .= ' c-jobs-section--is-closed';
endif;
echo '<div class="' . $classCSS . '">';
echo '<h3 class="c-jobs-section--heading">' . $section . '</h3>';
echo '<div class="c-jobs-section--content">';
echo '<ul class="c-jobs-section--list">';
foreach ( $res as $r ):
?>
<li class="c-jobs-section--item <?php if ($r['active']): echo 'c-jobs-section--item-active'; endif; ?>"><a href="<?php echo $r['href']; ?>" title="<?php echo $r['name']; ?>" class="c-jobs-section--anchor"><?php echo $r['name'] . ' (' . $r['total'] . ')'; ?></a></li>
<?php
endforeach;
echo '</ul>';
echo '</div>';
if ($isClosed):
echo '<a href="#" class="js-expand-jobs-section c-jobs-section--expand">' . __('More ...', 'biuro') . ' </a>';
endif;
echo '</div>';
endif;
}
function getSiteTree($type, $section, $searchQuery, $term) { function getSiteTree($type, $section, $searchQuery, $term) {
$res = array(); $res = array();
$termID = $term ? $term->term_id : ''; $termID = $term != '' ? $term->term_id : '';
$pages = getRecords($type, $searchQuery); $pages = getOptions($type);
foreach ( $pages as $page ): foreach ( $pages as $page ):
if ($page['pageID']) : if ($page['pageID'] && $page['status'] == 'publish') :
array_push($res, array( array_push($res, array(
'name' => $page['title'], 'name' => $page['title'],
'href' => getPageURL($type, get_page_link( $page['pageID'] ), $searchQuery, $page['termID']), 'href' => getPageURL($type, get_page_link( $page['pageID'] ), $searchQuery, $page['termID']),
...@@ -227,11 +84,15 @@ function getSiteTree($type, $section, $searchQuery, $term) { ...@@ -227,11 +84,15 @@ function getSiteTree($type, $section, $searchQuery, $term) {
endif; endif;
endif; endif;
if ($searchQuery['city']): $city = '';
$field = '';
$type = '';
if (isset($searchQuery['city'])):
$city = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['city']), 'city' ); $city = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['city']), 'city' );
endif; endif;
if ($searchQuery['s']): if (isset($searchQuery['s'])):
$field = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'field' ); $field = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'field' );
$type = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'type' ); $type = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'type' );
endif; endif;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment