dimanche 20 janvier 2019

WP_User_Query args multi select checkbox result display in wordpress

I have written custom search query for searching the instructor custom metadata it is working with the input type text, but I want to sort the result to display with the teaching type as Regular or Online / both selected with the checkboxes How do I get and store the results of checkboxes and pass the value to an array, to display the sorted results like selected Regular checkbox on display Regular teacher result, If selected online display only online If selected both show all the result. Currently, I have added metadata results for teaching type in the input field to display, but I want to sort the results by passing the values from checkboxes. I have added the code in WordPress searchform.php I not getting, how to implement it.

here is my code...

Thanks in advance.

<form role="search" method="get" id="searchform" class="form-inline" 
action="<?php echo home_url( '/' ); ?>">
<input type="checkbox" class="input-check" name="check_type" 
value="regular"  /><label>Regular</label>
<input type="checkbox" class="input-check" name="check_type" 
value="online" /><label>Online</label></br>

<input type="search" name="teacher" id="teacher" <?php if(is_search()) 
{ ?>value="<?php the_search_query(); ?>" <?php } else { ? 
>placeholder="Subjects / Skills"<?php } ?> /><br />

<input type="text" name="geolocate" value="" id="geo-id" class="geo- 
cl" placeholder="Location" />

<button type="submit" id="searchsubmit" value="Search">Search</button>
</form>


<?php
if( $_GET['teacher'] ) {

$search_term = sanitize_text_field( stripslashes( $_GET['teacher']));
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query_types = get_query_var('check_type');
?>
<div class="search-query-result">
    <p>You are searching for : <?php echo $search_term; ?> </p>
</div>

<?php

if($_POST['check_type']) {
            $teaching_type = $_POST['check_type'];
            $teaching_type = implode(',',$teaching_type);
        }
        else { $teaching_type            = ''; }

// WP_User_Query arguments
$args = array (
'role'       => 'lp_teacher',
'order'      => 'ASC',
'orderby'    => 'display_name',
'number'     => 999999,
'paged'      => $paged,
'meta_query' => array(
    'relation' => 'OR',
    array(
        'key'     => 'nickname',
        'value'   => $search_term,
        'compare' => 'LIKE'
    ),
    array(
        'key'     => 'last_name',
        'value'   => $search_term,
        'compare' => 'LIKE'
    ),
    array(
        'key'     => 'subjects',
        'value'   => $search_term,
        'compare' => 'LIKE'
    ),
    array(
        'key'     => 'online',
        'value'   => $query_types,
        'compare' => 'LIKE'
    ),
  //  array(
  //      'key'     => 'regular',
  //      'value'   => $search_term,
 //        'compare' => 'LIKE'
 //    ),
    array(
        'key'     => 'address',
        'value'   => $search_term,
        'compare' => 'LIKE'
    ),
    array(
        'key'     => 'occupation',
        'value'   => $search_term,
        'compare' => 'LIKE'
    ),
    array(
        'key'     => 'standard',
        'value'   => $search_term,
        'compare' => 'LIKE'
    )
)
);

// Create the WP_User_Query object
$wp_user_query = new WP_User_Query( $args );

// Get the results
$instructors = $wp_user_query->get_results();

// Check for results
if ( ! empty( $instructors ) )
{

foreach ( $instructors as $instructor ){
    $instructor_info = get_userdata( $instructor->ID );

  //  $curuser = get_userdata($user->ID);
     $author_post_url=get_author_posts_url($instructor_info->ID, 
$instructor_info->nicename);
      echo "<div class='inst-post-search'>";?>
        <?php
            echo "<a 
href='/wordpress/teacherclone/profile/$instructor_info->display_name' 
title='.$instructor_info->display_name.'>";
            echo "<h2>$instructor_info->display_name</h2>";
            echo '</a>'; ?>
         <p><label>Occupation : </label> <?php echo $instructor_info- 
>occupation; ?></p>
         <div class="clearfix user-loop">
             <div class="profile-img">
               <?php
                 echo get_avatar($instructor_info->user_email, '80', 
$avatar);
               ?>
             </div>
             <div class="profile-desc">
               <?php
                 echo $instructor_info->description;
               ?>
             </div>
         </div>
         <div class="profile-addr">
              <label>Address : </label>
              <?php echo $instructor_info->address. '|' 
.$instructor_info->country; ?>
         </div>
         <div class="profile-sub">
               <label>Qualifiaction : </label>
               <?php echo $instructor_info->education; ?><br>
               <label>Teaching Standard / Board : </label>
               <?php echo $instructor_info->standard; ?><br>

              <label>Subjects : </label>
              <?php echo $instructor_info->subjects; ?>
         </div>

         <ul class="profile-ul">
           <li class="profile-ul-li profile-li-first-child"><i 
class="fa fa-laptop" aria-hidden="true"></i> <?php echo 
$instructor_info->onlineexp; ?></li>
           <li class="profile-ul-li"><i class="fa fa-address-card" 
aria-hidden="true"></i> <?php echo $instructor_info->totalexp; ?></li>
           <li class="profile-ul-li"><i class="fa fa-usd" aria- 
hidden="true"></i> <?php echo $instructor_info->fees; ?> / per hour. 
</li>
           <li class="profile-ul-li"><i class="fa fa-star" aria- 
hidden="true"></i> <?php if ($instructor_info->online == 'online'){  
echo $instructor_info->online; } else {echo NA;} ?> / <?php if 
($instructor_info->regular == 'regular'){ echo $instructor_info- 
>regular;}
           else {echo NA;} ?> </li>
           <li class="profile-ul-li profile-li-last-child"><?php 
education_lms_course_ratings() ?> </li>


         </ul>
         <?php if(get_post_type() == 'lp_course'){ echo 'lp_course'; 
}?>

         <?php
            //echo '<p>'.$curuser->education.'</p>';
            //echo '<p>'.$curuser->onlineexp.'</p>';
            //echo '<p>'.$curuser->totalexp.'</p>';
            //echo '<p>'.$curuser->fees.'</p>';
      echo '</div>';

//    echo $instructor_info->first_name;
}
}
else {
?>
<div class="search-query-noresult">
      <p><?php echo 'Sorry! No results found for your query. Please 
try with proper search keywords.';?></p>
</div>
<?php }}?>




Aucun commentaire:

Enregistrer un commentaire