使用WP_User_Query

时间:2016-08-09 13:02:49

标签: wordpress search

是否可以使用WP_User_Query创建自定义搜索表单?

我正在呼叫用户进入一个页面,其中包含每个人要求的特定信息,但理想情况下我希望它是一个搜索表单,我可以在其中搜索用户,然后他们的信息显示在下面,而不是必须使用分页在大名单中找到它们。

这也是管理区域内的一个页面,它为其添加了另一个级别,我创建了一个非常基本的插件,其中一个页面将显示此信息。这是我与目前工作的联系 - http://focusedlearning.hcrlaw.com/courses-admin

分页在这个外部页面上运行正常,但在实际的管理区域中,这不是我面临的另一个问题,但可能是另一个问题!

如果有人有任何想法/地点,他们可以指出我会非常感激,我现在​​的代码在下面,但目前可能无关紧要,

提前致谢!

            <?php $total_users = count_users();
            $total_users = $total_users['total_users'];
            $paged = get_query_var('paged');
            $number = 20;?>

            <?php 
                $args = array(
                    'order' => 'ASC',
                    'orderby' => 'display_name',
                    'count_total' => 'true',
                    'role' => 'subscriber',
                    'offset' => $paged ? ($paged) * $number : 0,
                    'number' => $number,
                );?>



                <?php
                    $blogusers = get_users($args);?>

                        <?php // Array of WP_User objects.
                            foreach ( $blogusers as $user ) {?>

                <?php $userId = $user->ID;?>

                <?php  echo '<input type="text" value="' . esc_html( $user->display_name ) . '">';?>



                <div id="content">

                    <h2>Completed Courses</h2>


                <!-- COMPLIANCE-->



                    <?php
                        $post_args = array(
                            'post_type' => 'tribe_events',
                            'eventDisplay'=>'custom',
                            'start_date'     => date( 'Y-m-d H:i:s', strtotime( '-365 days' ) ),
                            'tax_query' => array(

                                array(
                                    'taxonomy' => 'tribe_events_cat',
                                    'field'    => 'slug',
                                    'terms'    => 'compliance',
                                    ),
                                        ),

                                        'meta_query' => array(
                                            array(
                                                'key' => 'associated_people',
                                                'value' => '"' . $userid . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
                                                'compare' => 'LIKE'
                                        )
                                    )
                                ); ?>

                    <!-- MEMBERSHIP A -->                       

                    <?php if( rcp_is_active() && 2 == rcp_get_subscription_id() ) : ?>

                        <?php
                        $post_list = new wp_query( $post_args ); ?>

                            <table style="width:100%">      
                                <tr>
                                    <td>Compliance</td>
                                </tr>

                                <?php
                                    if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                ?>

                                    <tr>
                                        <td><a href="<?php the_permalink();?>"><?php the_title(); ?></a></td>
                                        <td><?php the_field('cpd_credits'); ?></td>
                                    </tr>

                    <?php endwhile; else : ?>
                    <?php endif; wp_reset_query(); ?>


                    <?php

                    $total_credit = 0;

                    $post_list = new wp_query( $post_args ); ?>

                    <table style="width:100%">      

                        <?php
                            if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                $cur_credit = get_field('cpd_credits');
                                $total_credit += $cur_credit;
                        ?>


                        <?php endwhile; else : ?>
                        <?php endif; wp_reset_query(); ?>

                        <tr>
                            <td <?php if($total_credit >= 2): ?> style="background-color:#009137;" <?php endif; ?> <?php if($total_credit < 2): ?> style="background-color:#f50c1a;" <?php endif; ?>>
                                Total: <?php echo $total_credit;?> of 2 in the last 12 months
                            </td>
                        </tr>

                        </table>

                        <?php endif; ?>

                        <!-- END OF MEMBERSHIP A -->


                        <!-- MEMBERSHIP B -->                       

                    <?php if( rcp_is_active() && 3 == rcp_get_subscription_id() ) : ?>

                        <?php
                        $post_list = new wp_query( $post_args ); ?>

                            <table style="width:100%">      
                                <tr>
                                    <td>Compliance</td>
                                </tr>

                                <?php
                                    if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                ?>

                                    <tr>
                                        <td><a href="<?php the_permalink();?>"><?php the_title(); ?></a></td>
                                        <td><?php the_field('cpd_credits'); ?></td>
                                    </tr>

                    <?php endwhile; else : ?>
                    <?php endif; wp_reset_query(); ?>


                    <?php

                    $total_credit = 0;

                    $post_list = new wp_query( $post_args ); ?>

                    <table style="width:100%">      

                        <?php
                            if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                $cur_credit = get_field('cpd_credits');
                                $total_credit += $cur_credit;
                        ?>


                        <?php endwhile; else : ?>
                        <?php endif; wp_reset_query(); ?>

                        <tr>
                            <td <?php if($total_credit >= 2): ?> style="background-color:#009137;" <?php endif; ?> <?php if($total_credit < 2): ?> style="background-color:#f50c1a;" <?php endif; ?>>
                                Total: <?php echo $total_credit;?> of 2 in the last 12 months
                            </td>
                        </tr>

                        </table>

                        <?php endif; ?>

                        <!-- END OF MEMBERSHIP B -->

                        <!-- MEMBERSHIP C -->                       

                    <?php if( rcp_is_active() && 4 == rcp_get_subscription_id() ) : ?>

                        <?php
                        $post_list = new wp_query( $post_args ); ?>

                            <table style="width:100%">      
                                <tr>
                                    <td>Compliance</td>
                                </tr>

                                <?php
                                    if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                ?>

                                    <tr>
                                        <td><a href="<?php the_permalink();?>"><?php the_title(); ?></a></td>
                                        <td><?php the_field('cpd_credits'); ?></td>
                                    </tr>

                    <?php endwhile; else : ?>
                    <?php endif; wp_reset_query(); ?>


                    <?php

                    $total_credit = 0;

                    $post_list = new wp_query( $post_args ); ?>

                    <table style="width:100%">      

                        <?php
                            if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                $cur_credit = get_field('cpd_credits');
                                $total_credit += $cur_credit;
                        ?>


                        <?php endwhile; else : ?>
                        <?php endif; wp_reset_query(); ?>

                        <tr>
                            <td <?php if($total_credit >= 2): ?> style="background-color:#009137;" <?php endif; ?> <?php if($total_credit < 2): ?> style="background-color:#f50c1a;" <?php endif; ?>>
                                Total: <?php echo $total_credit;?> of 2 in the last 12 months
                            </td>
                        </tr>

                        </table>

                        <?php endif; ?>

                        <!-- END OF MEMBERSHIP C -->

                        <!-- MEMBERSHIP D -->                       

                    <?php if( rcp_is_active() && 5 == rcp_get_subscription_id() ) : ?>

                        <?php
                        $post_list = new wp_query( $post_args ); ?>

                            <table style="width:100%">      
                                <tr>
                                    <td>Compliance</td>
                                </tr>

                                <?php
                                    if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                ?>

                                    <tr>
                                        <td><a href="<?php the_permalink();?>"><?php the_title(); ?></a></td>
                                        <td><?php the_field('cpd_credits'); ?></td>
                                    </tr>

                    <?php endwhile; else : ?>
                    <?php endif; wp_reset_query(); ?>


                    <?php

                    $total_credit = 0;

                    $post_list = new wp_query( $post_args ); ?>

                    <table style="width:100%">      

                        <?php
                            if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                $cur_credit = get_field('cpd_credits');
                                $total_credit += $cur_credit;
                        ?>


                        <?php endwhile; else : ?>
                        <?php endif; wp_reset_query(); ?>

                        <tr>
                            <td <?php if($total_credit >= 2): ?> style="background-color:#009137;" <?php endif; ?> <?php if($total_credit < 2): ?> style="background-color:#f50c1a;" <?php endif; ?>>
                                Total: <?php echo $total_credit;?> of 2 in the last 12 months
                            </td>
                        </tr>

                        </table>

                        <?php endif; ?>

                        <!-- END OF MEMBERSHIP D -->




                        <!-- MEMBERSHIP E -->                       

                    <?php if( rcp_is_active() && 6 == rcp_get_subscription_id() ) : ?>

                        <?php
                        $post_list = new wp_query( $post_args ); ?>

                            <table style="width:100%">      
                                <tr>
                                    <td>Compliance</td>
                                </tr>

                                <?php
                                    if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                ?>

                                    <tr>
                                        <td><a href="<?php the_permalink();?>"><?php the_title(); ?></a></td>
                                        <td><?php the_field('cpd_credits'); ?></td>
                                    </tr>

                    <?php endwhile; else : ?>
                    <?php endif; wp_reset_query(); ?>


                    <?php

                    $total_credit = 0;

                    $post_list = new wp_query( $post_args ); ?>

                    <table style="width:100%">      

                        <?php
                            if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                $cur_credit = get_field('cpd_credits');
                                $total_credit += $cur_credit;
                        ?>


                        <?php endwhile; else : ?>
                        <?php endif; wp_reset_query(); ?>

                        <tr>
                            <td <?php if($total_credit >= 2): ?> style="background-color:#009137;" <?php endif; ?> <?php if($total_credit < 2): ?> style="background-color:#f50c1a;" <?php endif; ?>>
                                Total: <?php echo $total_credit;?> of 2 in the last 12 months
                            </td>
                        </tr>

                        </table>

                        <?php endif; ?>

                        <!-- END OF MEMBERSHIP E -->


                        <!-- END OF COMPLIANCE-->


            </div>  

            <?php }?>




             <?php $pl_args = array(
                 'base'     => add_query_arg('paged','%#%'),
                 'format'   => '',
                 'total'    => floor($total_users / $number),
                 'current'  => max(1, $paged),
              );

              // for ".../page/n"
              if($GLOBALS['wp_rewrite']->using_permalinks())
                $pl_args['base'] = user_trailingslashit(trailingslashit(get_pagenum_link(1)).'page/%#%/', 'paged');

              echo paginate_links($pl_args);?>

            </div>

0 个答案:

没有答案