1

I am hoping someone with more expertise can help me here. I tried passing specific args but the script wouldn't work as expected. Basically it lists all users who ticked a custom tick box that says they want their website or address showing on our "where to buy" page.

This is essentially an optimization question. I feel like passing the entire array is unnecessary but can't figure out how to pass specific ones without it being a search or comparison.

function user_list_shortcode($atts) {

    // WP_User_Query arguments
    $args_user_list = array(
        'fields' => 'all_with_meta',
    );

    // The User Query
    $user_query_user_list = new WP_User_Query( $args_user_list );

    // List generation
    $user_list_web = '<ul>';

    // The User Loop
    if ( ! empty( $user_query_user_list->results ) ) {
        foreach ( $user_query_user_list->results as $user1 ) {

            // if user's display website tick box is checked
            if ( $user1->wwlc_cf_includelink[0] ) {
                $user_list_web .=  '<li><a href="' . $user1->wwlc_cf_website . '" target="_blank">' .  $user1->wwlc_company_name . '</a></li>';
            }

            // if user's display address tick box is checked
            if ( $user1->wwlc_cf_includelink[1] ) {
                $user_list_web .=  '<li>' . $user1->wwlc_address . ' ' . $user1->wwlc_city . ', ' . $user1->wwlc_state . '</li>';
            }
        }
    }

    $user_list_web .= '</ul>';

    return $user_list_web;
    }

add_shortcode('user_list','user_list_shortcode');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.