Advertisement
ikamal7

all-jobs-post.php

Sep 23rd, 2020
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.04 KB | None | 0 0
  1. <?php
  2. $args = array(
  3.     'post_type'      => 'jobs',
  4.     'posts_per_page' => 5,
  5.     'post_status'    => 'publish',
  6.  );
  7.  
  8. $search_q  = get_query_var( 'sq' );
  9. $post_type = get_query_var( 'cpt' );
  10.  
  11. $type       = get_query_var( 'type' );
  12. $industry   = get_query_var( 'industry' );
  13. $location   = get_query_var( 'location' );
  14. $experience = get_query_var( 'experience' );
  15. $ql         = get_query_var( 'ql' );
  16.  
  17. if ( !empty( $search_q ) && $post_type == 'jobs' ) {
  18.     $args = array(
  19.         's'         => $search_q,
  20.         'post_type' => 'jobs',
  21.     );
  22. }
  23.  
  24. if ( !empty( $type ) ) {
  25.     if ( $type != 'all' ) {
  26.         $args['tax_query'] = array(
  27.             array(
  28.                 'taxonomy' => 'job-type',
  29.                 'field'    => 'slug',
  30.                 'terms'    => $type,
  31.             ),
  32.         );
  33.     } else {
  34.         $term_id = [];
  35.         $_terms  = get_terms( ['taxonomy' => 'job-type', 'hide_empty' => true] );
  36.         foreach ( $_terms as $_term ) {
  37.             $term_id[] = $_term->term_id;
  38.         }
  39.  
  40.         $args['tax_query'] = array(
  41.             array(
  42.                 'taxonomy' => 'job-type',
  43.                 'field'    => 'term_id',
  44.                 'terms'    => $term_id,
  45.             ),
  46.         );
  47.     }
  48. }
  49.  
  50. if ( !empty( $industry ) ) {
  51.     if ( $industry != 'all' ) {
  52.         $args['tax_query'] = array(
  53.             array(
  54.                 'taxonomy' => 'industry',
  55.                 'field'    => 'slug',
  56.                 'terms'    => $industry,
  57.             ),
  58.         );
  59.     } else {
  60.         $term_id = [];
  61.         $_terms  = get_terms( ['taxonomy' => 'industry', 'hide_empty' => true] );
  62.         foreach ( $_terms as $_term ) {
  63.             $term_id[] = $_term->term_id;
  64.         }
  65.         $args['tax_query'] = array(
  66.             array(
  67.                 'taxonomy' => 'industry',
  68.                 'field'    => 'term_id',
  69.                 'terms'    => $term_id,
  70.             ),
  71.         );
  72.     }
  73. }
  74.  
  75. if ( !empty( $location ) ) {
  76.     if ( $location != 'all' ) {
  77.         $args['tax_query'] = array(
  78.             array(
  79.                 'taxonomy' => 'job-location',
  80.                 'field'    => 'slug',
  81.                 'terms'    => $location,
  82.             ),
  83.         );
  84.     } else {
  85.         $term_id = [];
  86.         $_terms  = get_terms( ['taxonomy' => 'job-location', 'hide_empty' => true] );
  87.         foreach ( $_terms as $_term ) {
  88.             $term_id[] = $_term->term_id;
  89.         }
  90.         $args['tax_query'] = array(
  91.             array(
  92.                 'taxonomy' => 'job-location',
  93.                 'field'    => 'term_id',
  94.                 'terms'    => $term_id,
  95.             ),
  96.         );
  97.     }
  98. }
  99.  
  100. if ( !empty( $ql ) ) {
  101.     if ( $ql != 'all' ) {
  102.         $args['meta_query'] = array(
  103.             array(
  104.                 'key'     => 'qualification',
  105.                 'value'   => $ql,
  106.                 'compare' => 'LIKE',
  107.             ),
  108.         );
  109.     } else {
  110.         $args['meta_query'] = array(
  111.             array(
  112.                 'key'     => 'qualification',
  113.                 'compare' => 'EXISTS',
  114.             ),
  115.         );
  116.     }
  117. }
  118.  
  119. if ( !empty( $experience ) ) {
  120.     if ( $experience != 'all' ) {
  121.         $args['meta_query'] = array(
  122.             array(
  123.                 'key'     => 'experience',
  124.                 'value'   => strval( $experience ),
  125.                 'compare' => 'LIKE',
  126.             ),
  127.         );
  128.     } else {
  129.         $args['meta_query'] = array(
  130.             array(
  131.                 'key'     => 'experience',
  132.                 'compare' => 'EXISTS',
  133.             ),
  134.         );
  135.     }
  136. }
  137.  
  138. $query = new WP_Query( $args );
  139. if ( $query->have_posts() ) {
  140.     while ( $query->have_posts() ) {
  141.         $query->the_post();
  142.         $job_title      = get_the_title();
  143.         $companies_name = get_the_terms( get_the_ID(), 'company_tax' );
  144.         $job_industries = get_the_terms( get_the_ID(), 'industry' );
  145.         $terms_location = get_the_terms( get_the_ID(), 'job-location' );
  146.         $job_types      = get_the_terms( get_the_ID(), 'job-type' );
  147.         $post_view      = get_post_meta( get_the_ID(), 'tie_views', true );
  148.         $metas          = get_post_meta( get_the_ID() );
  149.         ?>
  150. <div class="job-post-single" id="job-post-single" data-ex-id="<?php echo get_the_ID(); ?>" data-type="<?php echo get_query_var( 'type' )[0]; ?>">
  151.   <div class="job-post-single-top">
  152.     <?php foreach ( $companies_name as $company_name ): ?>
  153.       <div class="job-post-single-top-leftbox">
  154.         <?php
  155. $t_id = $company_name->term_id;
  156.         // $term_meta = get_option( "company_tax_$t_id" );
  157.         $term_meta = get_term_meta( $t_id, 'company_term_meta', true );
  158.         ?>
  159.         <?php
  160. if ( $term_meta['company_logo'] != NULL ) {
  161.             echo '<img src="' . $term_meta['company_logo'] . '" alt="' . $company_name->name . '">';
  162.         } else {
  163.             echo '<img src="' . get_stylesheet_directory_uri() . '/assets/images/default_company_logo.jpg" alt="' . $company_name->name . '">';
  164.         }
  165.         ?>
  166.       </div>
  167.     <?php endforeach;?>
  168.     <div class="job-post-single-top-righttbox">
  169.       <a href="<?php echo get_the_permalink(); ?>"><h3><?php echo get_the_title(); ?></h3></a>
  170.       <?php foreach ( $companies_name as $company_name ): ?>
  171.         <span class="company_name"><?php echo $company_name->name; ?></span>
  172.       <?php endforeach;?>
  173.       <ul class="skill_list">
  174.         <h4><?php echo esc_html( 'Skills:' ) ?></h4>
  175.         <?php
  176. $skills_name = get_the_terms( get_the_ID(), 'skills' );
  177.         $i           = 0;
  178.         foreach ( $skills_name as $skill_name ):
  179.             if ( $i < 3 ) {
  180.                 ?>
  181.                         <li><span><?php echo $skill_name->name; ?></span></li>
  182.                         <?php $i++;}
  183.         endforeach;?>
  184.         <?php
  185. $skills_more      = get_the_terms( get_the_ID(), 'skills' );
  186.         $skill_more_count = count( $skills_more );
  187.         $skill_more_count = $skill_more_count - 3;
  188.         ?>
  189.         <?php if ( $skill_more_count > 0 ) {?>
  190.         <li class="count"><span><?php echo '+' . $skill_more_count . ' Others'; ?></span></li>
  191.         <?php }?>
  192.       </ul>
  193.     </div>
  194.   </div>
  195.   <div class="job-post-single-middle">
  196.     <ul class="info-list">
  197.       <li><strong><?php echo esc_html( 'Date:' ) ?></strong><?php echo "<span>" . get_the_date( "d " ) . get_the_date( "M" ) . ", " . get_the_date( "Y" ) . "</span>"; ?></li>
  198.       <li class="list-divider">//</li>
  199.       <li><strong><?php echo esc_html( 'Industry:' ) ?></strong><span><?php foreach ( $job_industries as $job_industry ): ?><?php echo $job_industry->name; ?><?php endforeach;?></span></li>
  200.       <li class="list-divider">//</li>
  201.       <li><strong><?php echo esc_html( 'Location:' ) ?></strong><span><?php foreach ( $terms_location as $term_location ): ?><?php echo $term_location->name; ?><?php endforeach;?></span></li>
  202.       <li class="list-divider">/</li>
  203.       <li class="view"><i class="fas fa-chart-area"></i><span><?php if ( $post_view > 0 && $post_view <= 999 ) {echo $post_view;} elseif ( $post_view > 1000 ) {$result = number_format(  ( $post_view / 1000 ), 2 ) . 'K';
  204.             echo $result;} else {echo "0";}?></span></li>
  205.     </ul>
  206.   </div>
  207.   <div class="job-post-single-bottom">
  208.     <p>
  209.       <?php
  210. $excerpt = get_the_excerpt();
  211.         $excerpt = substr( $excerpt, 0, 220 );
  212.         echo $excerpt . '...';
  213.         ?>
  214.     </p>
  215.   </div>
  216.   <?php foreach ( $job_types as $job_type ): ?>
  217.     <?php
  218. $color_id   = $job_type->term_id;
  219.         $color_meta = get_option( "taxonomy_$color_id" );
  220.         ?>
  221.     <div class="job-type-badge">
  222.       <i class="fas fa-heart"></i>
  223.       <span style="border: 2px solid <?php echo $color_meta['job_type_color']; ?>; color: <?php echo $color_meta['job_type_color']; ?>;"><?php echo $job_type->name; ?></span>
  224.     </div>
  225.   <?php endforeach;?>
  226.   <a class="job-single-view" href="<?php echo get_the_permalink(); ?>"><?php echo esc_html( 'View Details' ) ?></a>
  227. </div>
  228. <?php
  229. }
  230. }
  231. // echo do_shortcode('[ajax_load_more id="2021911578" container_type="div" css_classes="posts-container" post_type="jobs" scroll="false"]');
  232. wp_reset_query();
  233. ?>
  234.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement