I am using Ultimate Member, and have franchise owners as one user role and shops as a different role. On the franchise owner profile, I have included a shortcode (that I need help with) to display the shops they own. I have created a drop-down in the shop's profile that includes a list of franchise owners, and have set up the shops with the appropriate franchise owner.

The following is what I have so far for the shortcode I need help with:

 * Shortcode for Showing Shops on Franchisee Profile
 * Usage: [list_foshops owner="Bob Smith" userrole="shop"]
function fo_shops($atts) {
      $atts = shortcode_atts( array(
        'owner'     => $display_name,
        'userrole'  => '',
        ), $atts );
      $user_query = new WP_User_Query( array( 
        'meta_key' => franchise_owner,
        'meta_value' => $atts['owner'],
        'role__in'    => wp_parse_list( $atts['userrole'] ),
      ) );
      um_fetch_user( um_profile_id() );
      $display_name = um_get_display_name( um_profile_id() );

      $users = $user_query->get_results();
      if (!empty($users)) {
          $user_id = um_profile_id();
          $results = '<table class=folist_user_table>';
            foreach ($users as $user){
            $results .= '<tr>
                <td class=folist_user_table_container_full>
                    <table class=folist_shop_table_container>
                            <th class="folist_coverphoto" rowspan="3"><a href=/user/shop' . $user->Store_Number . '/><img class=fo_coverphoto src=/wp-content/uploads/ultimatemember/' . $user_id . '/cover_photo-300.jpg></a></th>
                            <th class="folist_user_storenum"><a href=/user/shop' . $user->Store_Number . '/>Store #' . $user->Store_Number . '</a></th>
                          <th class="folist_user_consultant">Business Consultant: ' . $user->Group . '</th>
                           <td class="folist_user_address" colspan="2">' . $user->Address . ', ' . $user->City . ' ' . $user->State . ' ' . $user->Zip_Code . '</td>
                           <td class="folist_user_mgr" colspan="2"><u>District Manager:</u> ' . $user->DM_Full_Name . ' | <u>Store Manager:</u> ' . $user->SM_Full_Name . '</td>
            $results .= '</table>';
       } else {
          $results =  'No shops found';
          return $results;
add_shortcode( 'list_foshops', 'fo_shops' );

Before you start asking questions, let me clarify why I've set parameters. The "owner" parameter is optional so that if I want to display shops by a certain franchise owner on a different page, I can do so using the same shortcode. The "userrole" parameter is there because I have different franchise owners in different states defined by different user roles. Some of the owners have shops in multiple states, but I want to separate them by using two shortcodes with different parameters.

When the "owner" parameter is not set, the goal is to automatically pull the display name of the profile that the code is on and use that instead. Unfortunately, it currently displays all of the shops that have a value inputted into meta key "franchise_owner."

Furthermore, I can't get the cover photo in the "foreach" section to appear correctly. It instead displays the franchise owner's cover photo.

Any help would be appreciated, as I've spent way too long on this today.

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.