shortcodes-members.php 3.17 KB
<?php 

add_shortcode('members-list', 'members_list');




function members_list(){
 
  try{


    $custom_args = array( 'number' => -1 );

    $custom_query = new \WP_User_Query($custom_args);
    $members = $wp_user_query->get_results();
    ob_start(); 
    $uniqid = uniqid();
      if (!empty($members)):
    ?>
        <div class="course-list resources">
            <label for="quicksearch">Search:</label><input type="text" id="quicksearch" placeholder="" />
            <div class="filters">
            <a href="#" id="filter-more">FILTERS <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></a>
            <div class="filter-group">
                <div class="category-filter-group ">
                  <div class="category">
                  <?php $terms = get_post_meta('437','_um_custom_fields', true);
                        foreach($terms['department_branch']['options'] as $term){ ?>
                            <div class="category-filter"> <input id="<?php echo $term ; ?>" value="<?php echo $term ; ?>" type="checkbox" class="sr-only"><label for="<?php echo $term; ?>"><?php echo $term; ?></label></div>
                      <?php }; ?>
                        </div>
                      </div>
                <div class="btn-group sort-button-group"> 
                  <button class="btn btn-light" data-sort-direction="asc" data-sort-value="0" type="button">Name <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button> 
                  <button class="btn btn-light" data-sort-direction="asc" data-sort-value="2" type="button">Date <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button> 
                </div> 
                </div>
             
            </div>
            </div>
            <table id="resources">
            <thead><tr><th class="hidden"></th><th></th><th class="hidden"></th><th></th></tr></thead>
              <tbody>
                <?php  foreach ($members as $members):
                             echo members($members->ID);
                      endforeach; ?>
              </tbody>          
            </table>
          </div>     
      <?php endif;
        wp_reset_query();
        $output = ob_get_clean(); 
        return $output;

    }catch(Throwable $e) { 
      error_log("members_list()". $e->getMessage()) ;
    }

}




function members($id){

  ob_start(); 
  $post = get_post($id);
  $text = str_replace(']]>', ']]&gt;', apply_filters( 'the_content', strip_shortcodes($post->post_content)));
  $excerpt_length = apply_filters( 'excerpt_length', 20 );
  $text = wp_trim_words( $text, $excerpt_length, ' ...' );
  $categories = get_the_terms( $id, 'mlo-category' );
  $cat ="";  
  ?>

 <tr class="table-like__item">
  <td class="item"><div class="item-content"><a target="_blank" role="button" href="<?php echo wp_get_attachment_url($id); ?>"><?php echo $post->post_title; ?></a><div>
  </td> 
  <td class="hidden"> <?php echo $cat; ?></td>
  <td class="hidden"><?php echo get_post_time('U',false, $id ); ?></td>
  <td>
  <a target="_blank" role="button" href="<?php echo wp_get_attachment_url($id); ?>" class="button">View</a>
</td>
</tr>
<?php
  $output = ob_get_clean();
  return $output;
}