Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Team page displaying all team/advisors regardless of category WordPress

  • REFUNDED

My WP Theme comes with a team page. However I require two team pages with different category of team members (team and advisors). Even though I've set up advisors as a separate category and defined the team page to display only Advisors category, both team pages display ALL, regardless of categorisation.

What changes do I need to make in the team template page to enable only the selected category to display? Below is the code from the team.php page.

Categories are called: team and advisors

Many thanks.


<?php
/*
Template Name: Team page
*/

global $wp_query;
$page_options = get_post_custom( $wp_query->get_queried_object_id() );
$page_title= get_the_title($wp_query->get_queried_object_id());

$page_post = get_page($wp_query->get_queried_object_id());
$content = apply_filters('the_content', $page_post->post_content);
$content = str_replace(']]>', ']]>', $content);

$leftSidebars=isset($page_options['leftSidebars'])?$page_options['leftSidebars'][0]:'';
$rightSidebars=isset($page_options['rightSidebars'])?$page_options['rightSidebars'][0]:'';

$sliderType=isset($page_options['sliderType'])?(int)$page_options['sliderType'][0]:0;
$slideItems=isset($page_options['slideItems'])?$page_options['slideItems'][0]:'';

if ($leftSidebars!='')
$leftSidebars=json_decode($leftSidebars);

if ($rightSidebars!='')
$rightSidebars=json_decode($rightSidebars);

if ($slideItems!='')
$slideItems=json_decode($slideItems);

$categories=isset( $page_options['wt-metabox-page-team-categories'] ) ? implode(",", $page_options['wt-metabox-page-team-categories'] ) : null;
$args=array("post_type"=>"team","orderby"=>"id","order"=>"asc","taxonomy"=>"team-category","paged" =>(int) get_query_var('paged'));
$categories=isset( $page_options['wt-metabox-page-portfolio-categories'] ) ? implode(",", $page_options['wt-metabox-page-portfolio-categories'] ) : null;
if($categories!=null)
{
$args["category"]=$categories;
}

$query = new WP_Query($args);
$i=0;

get_header();
?>
<section class="container">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="port_content">
<?php the_content(); ?>
</div>
<?php endwhile; endif; // end have_posts() ?>
<?php
if (is_array($leftSidebars))
{
if (count($leftSidebars)>0)
{
?>
<div class="one-fourth sidebar">
<?php
foreach ($leftSidebars as $item)
{
if ( is_active_sidebar( $item ) )
dynamic_sidebar( $item );
}
?>
</div>
<?php
}
}
?>
<div class="<?php
//do some logic to figure out the class from sidebar options
$item_limit=3; //by default
if (!is_array($leftSidebars))
$leftSidebars=array();
if (!is_array($rightSidebars))
$rightSidebars=array();
if (is_array($leftSidebars) || is_array($rightSidebars))
{
if (count($leftSidebars)>0 && count($rightSidebars)>0)
{
echo 'one-half';
$item_limit=1;
}
if (count($leftSidebars)>0 && count($rightSidebars)==0)
{
echo 'three-fourth last';
$item_limit=2;
}
if (count($leftSidebars)==0 && count($rightSidebars)>0)
{
echo 'three-fourth';
$item_limit=2;
}
if (count($leftSidebars)==0 && count($rightSidebars)==0)
{
echo 'one';
$item_limit=3;
}
} else
echo 'one';
?>">
<?php while ($query->have_posts()): $query->the_post(); ?>
<div class="one-fourth-team <?php if ($i>=$item_limit) { echo "last"; $i=0-1; } ?>">
<div class="team-member grey-img-team <?php echo get_post_class(); ?>">
<p><div class="img_wrapper"><?php echo get_the_post_thumbnail( get_the_ID(), '215x215',array("class"=>'',"alt"=>get_the_title())); ?></div></p>
<div class="content">
<div class="title-wrapper">
<h4 class="title"><?php the_title(); ?></h4>
<ul class="team-social-links">
<?php
$socials = get_post_custom(get_the_ID());
$twitter =isset( $socials['wt-team-twitter'] ) ? esc_attr( $socials['wt-team-twitter'][0] ) : '';
$facebook = isset( $socials['wt-team-facebook'] ) ? esc_attr( $socials['wt-team-facebook'][0] ) : '';
$skype= isset( $socials['wt-team-skype'] ) ? esc_attr( $socials['wt-team-skype'][0] ) : '';
$linkedin= isset( $socials['wt-team-linkedin'] ) ? esc_attr( $socials['wt-team-linkedin'][0] ) : '';
$google= isset( $socials['wt-team-google'] ) ? esc_attr( $socials['wt-team-google'][0] ) : '';
$flickr= isset( $socials['wt-team-flickr'] ) ? esc_attr( $socials['wt-team-flickr'][0] ) : '';
$rss= isset( $socials['wt-team-rss'] ) ? esc_attr( $socials['wt-team-rss'][0] ) : '';
$mail= isset( $socials['wt-team-mail'] ) ? esc_attr( $socials['wt-team-mail'][0] ) : '';
?>
<?php if ($twitter!='')
{
?>
<li class="twitter"><a href="<?php echo $twitter; ?>"><?php echo __("Twitter","businessbox"); ?></a></li>
<?php } ?>
<?php if ($facebook!='')
{
?>
<li class="facebook"><a href="<?php echo $facebook; ?>"><?php echo __("Facebook","businessbox"); ?></a></li>
<?php } ?>
<?php if ($skype!='')
{
?>
<li class="skype"><a href="<?php echo $skype; ?>"><?php echo __("Skype","businessbox"); ?></a></li>
<?php } ?>
<?php if ($linkedin!='')
{
?>
<li class="linkedin"><a href="<?php echo $linkedin; ?>"><?php echo __("LinkedIn","businessbox"); ?></a></li>
<?php } ?>
<?php if ($google!='')
{
?>
<li class="googleplus"><a href="<?php echo $google; ?>"><?php echo __("Google+","businessbox"); ?></a></li>
<?php } ?>
<?php if ($flickr!='')
{
?>
<li class="flickr"><a href="<?php echo $flickr; ?>"><?php echo __("Flickr","businessbox"); ?></a></li>
<?php } ?>
<?php if ($rss!='')
{
?>
<li class="rss"><a href="<?php echo $rss; ?>"><?php echo __("RSS","businessbox"); ?></a></li>
<?php } ?>
<?php if ($mail!='')
{
?>
<li class="mail"><a href="<?php echo $mail; ?>"><?php echo __("Mail","businessbox"); ?></a></li>
<?php } ?>
</ul>
</div>
<p class="about"><?php the_content(); ?></p>
</div>
</div>
</div>
<?php $i++; endwhile; ?>
<div class="pagination with-margin">
<?php
bb_pagination($query);
?>
</div>
<?php
// Reset Query
wp_reset_query();
?>
</div>
<?php
if (is_array($rightSidebars))
{
if (count($rightSidebars)>0)
{
?>
<div class="one-fourth sidebar last">
<?php
foreach ($rightSidebars as $item)
{
if ( is_active_sidebar( $item ) )
dynamic_sidebar( $item );
}
?>
</div>
<?php
}
}
?>
</section>
<?php
get_footer();
?>

Answers (3)

2015-06-08

Darlene Grace Arcenal answers:

try changing this part:

$args=array("post_type"=>"team","orderby"=>"id","order"=>"asc","taxonomy"=>"team-category","paged" =>(int) get_query_var('paged'));

to this:
$args = array(
'post_type' => 'team',
'orderby'=> 'id',
'order'=>'asc',
'tax_query' => array(
array(
'taxonomy' => 'team-category',
'field' => 'slug',
'terms' => array( 'team' ),
)
),
'paged' =>(int) get_query_var('paged')
);


nk2nd comments:

No unfortunately this didn't work - just removed the advisors from the page and now the two pages show just the team members not the experts.

2015-06-08

timDesain Nanang answers:

try to change:

$categories=isset( $page_options['wt-metabox-page-team-categories'] ) ? implode(",", $page_options['wt-metabox-page-team-categories'] ) : null;
$args=array("post_type"=>"team","orderby"=>"id","order"=>"asc","taxonomy"=>"team-category","paged" =>(int) get_query_var('paged'));
$categories=isset( $page_options['wt-metabox-page-portfolio-categories'] ) ? implode(",", $page_options['wt-metabox-page-portfolio-categories'] ) : null;
if($categories!=null)
{
$args["category"]=$categories;
}

$query = new WP_Query($args);


with:

$team_categories = isset( $page_options['wt-metabox-page-team-categories'] ) ? implode(",", $page_options['wt-metabox-page-team-categories'] ) : null;
$port_categories = isset( $page_options['wt-metabox-page-portfolio-categories'] ) ? implode(",", $page_options['wt-metabox-page-portfolio-categories'] ) : null;

$args = array(
"post_type" => "team",
"orderby" => "ID",
"order" => "ASC",
"paged" => (int) get_query_var('paged')
);

if($team_categories!=null){
$args["team-category"] = $team_categories;
}

$query = new WP_Query($args);


nk2nd comments:

No unfortunately this didn't work - removed all members from both pages.

2015-06-08

Arnav Joy answers:

please find this line

$query = new WP_Query($args);

so I will provide you new $args as $args1

$args1=array("post_type"=>"team","orderby"=>"id","order"=>"asc","team-category"=>"team","paged" =>(int) get_query_var('paged'));

then place this $args1 to WP_Query

$query = new WP_Query($args1);

please note that the slug of the "Team" Category should be "team" or if it is not then change this line in right side

"team-category"=>"team"

and for "advisors" the slug should be "advisors" and as

"team-category"=>"advisors"

so final will be as

$args1=array("post_type"=>"team","orderby"=>"id","order"=>"asc","team-category"=>"advisors","paged" =>(int) get_query_var('paged'));

please check these and let me know if there is any issue.


nk2nd comments:

Hi, I'm a bit confused with your answer.

Do I add both these lines of code in and change $query = new WP_Query($args); to $query = new WP_Query($args1); ?

$args1=array("post_type"=>"team","orderby"=>"id","order"=>"asc","team-category"=>"team","paged" =>(int) get_query_var('paged'));
$args1=array("post_type"=>"team","orderby"=>"id","order"=>"asc","team-category"=>"advisors","paged" =>(int) get_query_var('paged'));

Thanks for clarification in advance.