Skip Navigation

[Resolved] Separating out category and sub category content

This support ticket is created 5 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 22 replies, has 3 voices.

Last updated by emilyT 5 years ago.

Assisted by: Shane.

Author
Posts
#1354401

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Emily,

Would you mind allowing me to have admin access too the site so that I can check on this for you ?

The private fields have been enabled for your next response.

Thanks,
Shane

#1355805

Hi Shane

Thanks for offering to have a look. What I'm going to do is set up a test version of the site which I will then give you access to. I'll be in touch shortly with the details.

Cheers, Emily

#1356253

Hi Shane

Could you switch the private fields on again please so I can give you access to the dev site?

Cheers, Emily

#1357979

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Emily,

Sorry for the delay in response.

Here are the private fields once more.

Thanks,
Shane

#1360067

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Emily,

Thank you for the credentials.

Have a look at the link here hidden link

I assume this is exactly what you want.

I achieved this by using 2 additional views and removing the loop output content on the archive and replace it with a view.

Firstly I created the view here.
hidden link

This view will list out the Posts of only the parent category when the hook below is applied.


add_filter( 'wpv_filter_query', 'not_all_my_children_term_filter',99,3 );
function not_all_my_children_term_filter( $query_args, $views_settings, $view_id) {
  $view_ids = array( 70 );
  if (in_array($view_id, $view_ids)){
    foreach($query_args['tax_query'] as $tq) {
      if( isset( $tq['taxonomy'] ) ){
        $tax = $tq['taxonomy'];
        $term = get_term_by('id', $tq['terms'], $tax);
        $termChildren = isset( $term->term_id ) ? get_term_children($term->term_id, $tax) : null;
        $query_args['tax_query'][] = array(
          'taxonomy' => $tax,
          'field' => 'id',
          'terms' => $termChildren,
          'operator' => 'NOT IN'
        );
      }
    }
  }
  return $query_args;
}

Next I added this view to the archive so it lists out only the posts of the parent.

I then created a second view that will list out the posts of the child view.

hidden link

Then I added this view to the view you are using to list out the sub categories so that each post can be listed under the relevant sub category.

Please let me know if this helps.

Thanks,
Shane

#1360835

Hi Shane

That looks perfect! I think you've gone a little further than I expected, but I love that it's all on the same page. I will have a go at recreating this on the main domain and we should then be good to go!

Thanks for your help with this, you've been amazing. I'm not closing the ticket for the moment as I would like to have a go at recreating it first - I'll let you know when I've done that successfully.

Best wishes, Emily

#1361407

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Emily,

Happy I was able to assist you.

Please let me know if you need any clarity on this.

Thanks,
Shane

#1364655

Thanks Shane, all sorted. Thanks for your help with this, your help was very much appreciated.