How to create a member directory

List your members (with published images) using the [ip-member-directory] shortcode. Copy the following snippet to your theme’s functions.php file:

add_shortcode('ip-member-directory', 'ip_member_directory');

function ip_member_directory_user_query($args) {
    $ip_slug = get_imagepress_option('ip_slug');
    $args->query_from = str_replace("post_type = post AND", "post_type IN ('$ip_slug') AND ", $args->query_from);
}

function ip_member_directory() {
    global $wpdb;

    $out = '';

    add_action('pre_user_query','ip_member_directory_user_query');
    $members = get_users(array(
        'fields' => array('ID', 'display_name'),
        'orderby' => 'post_count',
        'who' => 'authors',
        'has_published_posts' => get_post_types(array('public' => true)),
    ));
    remove_action('pre_user_query','ip_member_directory_user_query');

    $ipProfilePageId = (int) get_imagepress_option('ip_profile_page');
    $ipProfilePageUri = get_permalink($ipProfilePageId);
    $ipProfileSlug = (string) get_imagepress_option('cinnamon_author_slug');

    $out .= '<div>';
        foreach ($members as $group) {
            $ipProfileUri = $ipProfilePageUri . '?' . $ipProfileSlug . '=' . get_the_author_meta('user_login', $group->ID);
            $out .= '<div style="float:left;width:33%;">
                <a href="' . $ipProfileUri . '">' . $group->display_name . '</a>
            </div>';
        }
    $out .= '</div>';

    return $out;
}

Enjoy!

Unlimited Automated Page Speed Monitoring & Tracking. Completely free.
Use SpeedFactor to track your website. It’s simple, reliable, and best of all, it’s free forever.
See how real people experience the speed of your website. Then find (and fix) your web performance problems.
Get Started

Related Articles


Privacy Policy