Build Your Own Business Website header image

Welcome to our Members Only Forum

You are welcome to view the content on our Forum, just scroll down to view this forum post.
If you like what you find and want to be able to post a question, please check out our subscription options.
Please feel free to search the forum using either the Google Site Search above or the forum search below.

Avatar
Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Exclude Subcategories in a Loop
Avatar
Klaus
Member
Members
Forum Posts: 20
Member Since:
September 25, 2013
sp_UserOfflineSmall Offline
1
December 1, 2013 - 5:23 am
sp_Permalink sp_Print sp_EditHistory

Hi,

in the past i used a peace of Code in the Thesis master.php file. It excludes the subcategorie-posts from the parents categories.

Now my Hoster (Bluehost) switch from PHP 5.3 to PHP 5.4 next Week. I have test my Webssite and if i switch to PHP 5.4 the Website has a blank white Screen. The Error Log and the Code  below.

Can anyone give me a hint, how to change the code so that it also works in version PHP 5.4?

Thanks and regards

Klaus

 

This is the Code i use in PHP 5.3:

// Exclude Subcategories in a Loop
function fb_filter_child_cats($query) {
    
    $cat = get_term_by('name', $query->query_vars['category_name'], 'category');
    $child_cats = (array) get_term_children( &$cat->term_id, 'category' );
    // also possible
    // $child_cats = (array) get_term_children( get_cat_id($query->query_vars['category_name']), 'category' );
    
    if ( !$query->is_admin )
        $query->set( 'category__not_in', array_merge($child_cats) );
    
    return $query;
}
add_filter( 'pre_get_posts', 'fb_filter_child_cats' );

 

The Error-Log:

[01-Dec-2013 13:06:06 UTC] PHP Fatal error:  Call-time pass-by-reference has been removed; If you would like to pass argument by reference, modify the declaration of get_term_children(). in /home1/xxxxxx/public_html/xxxxxxx/wp-content/thesis/master.php on line 34

 

Line 34: $child_cats = (array) get_term_children( &$cat->term_id, 'category' );

Avatar
Klaus
Member
Members
Forum Posts: 20
Member Since:
September 25, 2013
sp_UserOfflineSmall Offline
2
December 1, 2013 - 6:18 am
sp_Permalink sp_Print

Hi,

 

i have found the solution:

For all who have a similar problem:

In the Line:  $child_cats = (array) get_term_children( &$cat->term_id, 'category' );

I remove the '&' and now it works for me.

 

Regards

Klaus

Avatar
Keith W Jones
Somerset, UK
Member
Members

Community Member
Forum Posts: 1428
Member Since:
June 22, 2013
sp_UserOfflineSmall Offline
3
December 1, 2013 - 6:23 am
sp_Permalink sp_Print

Thanks Klaus for giving the answer. Could well help someone else.

Keith

Keith W Jones
Make sure you backup before upgrading and making changes.
Best results when one question per thread, link to site, version of WP, Thesis and skin.
http://www.kwjassociates.co.uk - Wordpress 5.1.1 – Thesis 2.8.5 - Focus

 

*** Biggest cause of problems is now the cache, whether it is a plugin, the browser or your host's server. ***
*** Do not edit Skin and Editor CSS - make changes using Custom CSS. ***
*** Do not edit core files - make changes using custom.php or master.php. ***
Avatar
Rick Anderson
Desert Hot Springs, CA
Admin
Forum Posts: 13637
Member Since:
November 8, 2009
sp_UserOfflineSmall Offline
4
December 1, 2013 - 9:38 am
sp_Permalink sp_Print

I wouldn't have noticed that.  Thanks for sharing the answer.

Forum Timezone: America/Los_Angeles

Most Users Ever Online: 228

Currently Online:
18 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Keith W Jones: 1428

Brian Tozer: 1004

Carolin: 982

Heidi Hafner: 508

John Cunningham: 423

Reece Morrel: 353

Newest Members:

emma62755

sharonmarks

emma80233

Tijs de Jong

Daniel Frey

mutek

Forum Stats:

Groups: 8

Forums: 46

Topics: 6995

Posts: 34796

 

Member Stats:

Guest Posters: 6

Members: 6761

Moderators: 2

Admins: 2

Administrators: Rick Anderson, Rick Anderson

Moderators: Pierre Cote, Laura Nugent