Here is the code I use to display shops of each current profile as a TAB, but doesn’t work properly:
/* ADD NEW PROFILE TABS IN PROFILE */
if ( is_user_logged_in() ) {
//Get currently logged in user:
global $current_user;
get_currentuserinfo();
//For each ROLE:
switch (true) {
//IF BARBER:
case ( user_can( $current_user, "barber") ):
add_shortcode('list_shops_in_current_profile', 'display_shops_in_current_profile', 10, 1);
break;
//IF BARBER SHOP:
case ( user_can( $current_user, "barber_shop") ):
add_shortcode('list_shops_in_current_profile', 'display_shops_in_current_profile', 10, 1);
break;
//IF ADMINISTRATOR:
case ( user_can( $current_user, "administrator") ):
add_shortcode('list_shops_in_current_profile', 'display_shops_in_current_profile', 10, 1);
break;
}
}
function display_shops_in_current_profile(){
//Get user id of displayed profile:
$user = uwp_get_displayed_user();
$role = $user->roles[0];
$id = $user->ID;
//Query to return shops using user's id:
$post_query = new WP_Query(array(
'author' => $id,
'post_type' => 'gd_place'
));
//If results not null:
if($post_query->have_posts() ) {
$numOfShops = $post_query->found_posts;
?>
<!-- CREATE CONTAINER TO HOLD SHOPS -->
<br>
<br>
<div class="container">
<div class="row">
<?php
//FOR EACH POST CREATE A CARD:
while($post_query->have_posts()) {
$post_query->the_post();//GET POST OBJECT
$i = $post_query->current_post;//GET LOOP INDEX
$BS_location_id = get_the_id();//GET POST ID
$view_BS_loction_URL = get_the_permalink();//URL FOR VIEW LOCATION
?>
<div class="col-lg-4 d-flex align-items-stretch mb-4">
<div class="card">
<img style ="width: auto; height: 200px; object-fit: cover;" src="
<?php
if (has_post_thumbnail()) {
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail_name');
echo $thumb[0]; // thumbnail url
}
?>
" class="card-img-top" alt="">
<div class="card-body">
<h5 class="card-title"><?php the_title(); ?></h5>
<?php echo do_shortcode("[gd_single_taxonomies taxonomy='' prefix='' link_style='' link_color='' link_color_custom='' link_icon='false' mt='' mr='' mb='2' ml='' pt='' pr='' pb='' pl='' ]
");?>
</div>
<div class="card-footer d-grid gap-2">
<a class="btn btn-primary w-100" href="<?php echo $view_BS_loction_URL?>" role="button" style="margin-top:6px;"><i class="fas fa-eye"></i> View Shop</a>
</div>
</div>
</div>
<?php
//Create new row after 3rd element
if(($i+1) % 3 == 0){
?>
</div> <!-- End of first initial row -->
<div class="row">
<?php
}
} //end of while loop
?>
</div> <!-- End of final Row -->
</div> <!-- End of Container -->
<?php
}//end of if statement (post_query)
else{ //if user doesn't have shops
?>
<h1 style="color:white;">This user doesn't not have a shop yet</h1>
<?php
}
}