getButterfly
Resume

NAVIGATION

ATTRIBUTION

getButterfly
Dublin, Ireland

All Content Copyright ©2019
getButterfly

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!

Do you want better SEO? More traffic? More conversions? More growth? We help companies exponentially grow their traffic and conversions, while outranking their competitors. With more than 10 years of experience, we’ve learned what is valuable to our clients.
SEO Dublin | SEO Malta

My Battle Tested Recommendations

Jetpack
Dreamhost
WordPress.com
CodeCanyon
SEMrush

Disclaimer: These recommendations contain affiliate links.


Privacy Policy