Custom Looper Problem

Hello,
This is more of a WordPress issue but I hope you can help.

I am using a Custom Looper. My goal is to show sub-category (child category) names of the main category, called “Content Type”.

My custom looper looks like this…

Screenshot 2021-11-02 111242

and I have the below code in function.php:

add_filter( 'cs_looper_custom_my_data', function( $result ) {
	$subcats=get_categories(array('child_of' => 47, 'taxonomy'=>'category', 'hide_empty'=>0));
	return $subcats;
});

For some strange reason, if I remove 'child_of'=>47 the loop will return all categories, parent and child. But when I insert that clause, it gives me a blank. The Category ID is 47 (as shown in the above image). I just cannot figure out what’s wrong.

Any clues?

Many thanks in advance.

Hi @sgchan,

Thanks for reaching out.
I have checked the code in my local environment and it is working perfectly fine. I would suggest you check the Category ID once again if that is not correct. If that is not the case, please provide login credentials for your site in a secure note to examine it further, including:

– WordPress Site URL & Login URL
– WordPress Admin username/password
– FTP/CPanel credentials to access the files

To create a secure note, click the key icon underneath any of your posts.

Thanks

@tristup - Thank you for responding… I have included the credentials for your review. Many thanks in advance.

Hey @sgchan,

To get your issue resolved, kindly follow the solution in this thread:

Best Regards.

@tristup - I’d like to take up on your offer to examine further. Unfortunately, @ruenel’s answer is not satisfactory. His recommended article was how I learned of Custom Loopers.

Please help.

Hi @sgchan,

Please let us know if you need any further help with this.

Thanks

@tristup - Yes, I still do. As requested by you, I have added the secure note.

Hello @sgchan,

I have tested your code on my local testing server:

add_filter( 'cs_looper_custom_my_data', function( $result ) {
	$subcats=get_categories(array('child_of' => 75, 'taxonomy'=>'category', 'hide_empty'=>0));
	return $subcats;
});

I replace the 47 to 75 because this is my parent category ID and it is working for me.

It seems that there is something in your category set up that prevents it from displaying. Try comparing these two codes:

This does not return anything:

add_filter( 'cs_looper_custom_my_data', function( $result ) {
	$subcats=get_categories(array('child_of' => 47, 'taxonomy'=>'category', 'hide_empty'=>0));
	var_dump($subcats);
	return $subcats;
});

This will return the array:

add_filter( 'cs_looper_custom_my_data', function( $result ) {
	$subcats=get_categories(array( 'taxonomy'=>'category', 'hide_empty'=>0));
	var_dump($subcats);
	return $subcats;
});

Please try your code in another setup. Best Regards.

@ruenel - Thank you for testing. I concur with your findings as they are the same as mine. I am suspecting this is a Wordpress corruption. You may close the case. Again, thank you!

You are most welcome @sgchan

Hi @bogarguz,

By withdrawing the post, I believe you already have resolved the issue. If the issue still existed, you can let us know.

Thanks

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