Looper Provider Quesion

Hi, I am trying to show subcategories only of a post category in a Term Cloud. see screenshot, in this case the “Nutrition Blog” has a lot of subcategories

In this setup… i am getting it to work, BUT…I am getting duplicate “terms”. Why is this happening, and how can i stop it from duplicating the terms?

Hello Riceman,

Thanks for writing in! Are you using the Looper Provider All Terms or just the Looper Provider Current Terms? We would to check your set up. Please with us your WP details. You can create a secure note in your next reply with the following info:
– Link to your site
– WP login URL
– WP username
– WP password
– WP Administrator Role
– Confirmation that we can access and make changes to your site

To know how to create a secure note, please check this out: How The Forum Works

image

Best Regards.

Sure, see access in secure note. Thanks!

The Archive Layout is named Blog:
Screenshot 2023-12-23 at 5.39.20 PM

Right now I am keeping the Terms element hiddent, until I get it working properly. You can see the location of it in the screenshot. Please keep it hidden, even if you can get it working. Thanks.

Hey Riceman,

To display only the subcategory, please check out this thread instead:

Kindly let us know how it goes.

Thanks! I did find this thread before asking for help…but am not having any luck.

These are not product categories, so I adjusted the code:
add_filter(‘cs_looper_custom_subcat’, function($result, $args)
{

$category = get_queried_object();

$cat_args = array(
‘hide_empty’ => 1,
‘child_of’=> $category->term_id,
‘taxonomy’ => ‘$category’,

);

$subcats = get_categories($cat_args);
return $subcats;
}, 10, 2);

and this is what I am seeing/using under custom with no luck, tried “subcat” & “subcats”:

Hey Riceman,

Can you please update the PHP code into this instead:

add_filter('cs_looper_custom_subcat', function($result, $args){

    $category = get_queried_object();

    $cat_args = array(
    'hide_empty' => 1,
    'child_of'=> 1,
    'taxonomy' => '$category',

);

Kindly let us know how it goes.

Thanks… but still no luck. What am i missing?

ps. Im using Code Snippets to install this php code.
Screenshot 2023-12-26 at 10.50.28 AM

Hi Riceman,

The code should work. I would suggest you try adding the code to the functions.php of your child theme.

Thanks

OK, maybe that tool doesnt work. Its new to me. I did asdd the code in the functions file (child theme, see screenshot), still no luck with using any of these: subcat,subcats,category as the hook

My Custom Looper Provider looks different than the thread link you sent, but theirs may be an old version… maybe thats the problem?

Hey Riceman,

I’ve tried to debug the Custom Looper. Still, I couldn’t see the code properly and suspect that the credentials provided are not fully administrator because I cannot see the appearance option to check the code. That being said, please give us a credential with full access to your website.

Thank you.

i have it disabled. but you can access via cpanel. see secure note. thanks

Hey Riceman,

Instead of using this code:

// Blog Subcategories
add_filter('cs_looper_custom_subcat', function($result, $args){

    $category = get_queried_object();

    $cat_args = array(
    'hide_empty' => 1,
    'child_of'=> 1,
    'taxonomy' => '$category',

);
	
	$subcats = get_categories($cat_args);
return $subcats;
}, 10, 2);

I updated the code to this one:

// Blog Subcategories
add_filter('cs_looper_custom_subcat', function($result, $args){

    $category = get_queried_object();

    $cat_args = array(
        'hide_empty' => 1,
        'child_of'   => $category->term_id,
        'taxonomy'   => $category->taxonomy,
    );

    $subcats = get_categories($cat_args);

    return $subcats;
}, 10, 2);

In this corrected code:

  • I replaced the $category in the 'taxonomy' => '$category' line with $category->taxonomy .
  • I used $category->term_id for the 'child_of' parameter to get the term ID of the current category.

With those changes, it is now showing the correct subcategories with no duplications.

Hope that helps.

Thanks… looks good in the screenshot… but I am getting this:

I also am assuming I can remove these bits of code that was entered in WPcode. I did disable them as you can see.

Hey Riceman,

I suspect that the changes I have made was overwritten. That being said, I re-applied it. Please see the following items below:

In the Hook, instead of using ruesubcat, I changed it to subcat

image

Then in the term name text, the looper debugger code is added in the text, I removed it:

{{dc:term:name}} ({{dc:term:count}}) - - {{dc:looper:debug_consumer}}

This is now how it looks like:

Hope that helps.

Thanks so much. That did it!! Sorry if I overwrote the original code, not sure how i might have done that.

One final question. is it possible to have these subcategories also show up on the subcategory archive page?

ie: when Childhood Nutrition is selected and the user is taken to the Childhood Nutrition archive page, can the list of Nutrition Blog subcategories be shown here as well?

Issue that may arise is that we have other archive pages like “Recipes”, “Podtalks”, “Events” & “Past-Events”. We would NOT want the subcategories to show on these.

Hey Riceman,

Yes, it is doable to show the subcategories of the parent category to a subcategory. To do that, please update the code in the functions.php

// Blog Subcategories
add_filter('cs_looper_custom_subcat', function($result, $args){

    $category = get_queried_object();

    if ($category->parent != 0) {
        // If the current category has a parent, get the parent's subcategories
        $parent_cat_args = array(
            'hide_empty' => 1,
            'child_of'   => $category->parent,
            'taxonomy'   => $category->taxonomy,
        );

        $subcats = get_categories($parent_cat_args);
    } else {
        // If the current category is a parent, get its subcategories
        $cat_args = array(
            'hide_empty' => 1,
            'child_of'   => $category->term_id,
            'taxonomy'   => $category->taxonomy,
        );

        $subcats = get_categories($cat_args);
    }

    return $subcats;
}, 10, 2);

Upon checking on your setup, this won’t show on the other archive pages like “Recipes”, “Podtalks”, “Events” and “Past-Event”.

Hope that helps.

Yes, that helps! Thank you so much. You guys are the best.

You are most welcome, Riceman.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.