0

I am working on a portfolio site and I need to modify this part. It is a filter of categories, placed via a shortcode.

I want to show only the children categories of the selected category of my custom post type.... but I dont know how to call the parent variable to use it... I want to declare a variable for the parent so I can use it in the terms array...

add_shortcode( 'zee_portfolio', function( $atts, $content = null ){
$atts = shortcode_atts(
array(
'column' => '3',
'category' => '0'
), $atts);

extract($atts);

$args = array(
'posts_per_page' => -1,
'post_type'      =>  'zee_portfolio'
);

if(  $category > '0' ){
$args['tax_query'] = array(
  array(
    'posts_per_page' => -1,
    'taxonomy' => 'cat_portfolio',
    'field' => 'term_id',
    'terms' => $category
    )
  );
 }

$portfolios = get_posts( $args );

ob_start();

if(count($portfolios)>0){ ?>
<div id="portfolio" class="clearfix">
<ul class="portfolio-filter">
<li><a class="btn btn-default active" href="#" data-filter="*"><?php _e('All',TEXTDOMAIN); ?></a></li>
<?php 
$terms = get_terms('cat_portfolio', array('hide_empty'=> true));
foreach ($terms as $term) {
  ?>
  <li><a class="btn btn-default" href="#" data-filter=".<?php echo $term->slug; ?>"><?php echo $term->name; ?></a></li>
  <?php
}
?>
</ul>
0

Ok I finally notice what is it that I have to do! :D The variable was already set in the array in the shortcode atts.

All I had to do was set the parent=$category in the before the filter:

$terms = get_terms('cat_portfolio', array('hide_empty'=> true, 'parent'=> $category));

For wordpress developers maybe this is very easy but I am learning. Hope this helps someone.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.