Code Snippit worked in 4.1.5 doesn't work in 4.2

General questions pertaining to how certain issues can be resolved
Forum rules
1. No offensive language and no mocking
2. Please do a thorough search before you post something. Trust us, there is a high probability that the question you are asking has been asked previously.
3. No soliciting. You cannot post here soliciting bids for people offer you quotes, or even offer money to people for some work. You will be moderated if you do so. If you are looking for help, please post your request on http://jobs.wordpress.net or http://codepoet.com
4. Please be reasonable. You are getting software and support. For free. Complicated requests from a general purpose theme are not welcome and some volunteers might lose patience with you.
5. Please do your due diligence. If you posted a query and we answered with a link, take the trouble to go through the link contents.
6. Please post with complete information. Requests for help MUST be accompanied with your URL, particularly if you are asking something like "Why am I seeing a blank space?"

Code Snippit worked in 4.1.5 doesn't work in 4.2

Postby lionscience » 09 May 2012, 19:06

Hoping I can get this working.

I've been using a custom code shippit Thesistut (http://thesistut.com/2012/exclude-posts ... -category/) to exclude posts from children categories. this snippit worked fine in version 4.1.5, but after upgrading to 4.2 and adding it in the site breaks.

The code snippit goes into the functions.php file. It looks like this:
Code: Select all
/* disable posts from child categories in main query */
add_filter('pre_get_posts','custom_csp_pre_get_posts',20,1);
function custom_csp_pre_get_posts($query) {
    if(function_exists('is_main_query')) {
        if($query->is_category && !$query->is_admin && !$query->is_preview && $query->is_main_query() && false == $query->query_vars['suppress_filters']) {
            $cat = get_term_by( 'slug', $query->query_vars['category_name'], 'category');
            $query->set('category__in',$cat->term_id);
        }
    }
    return $query ;
}


I'd absolutely positively love to know how to fix it or barring that be able to download 4.1.5 and downgrade
lionscience
 
Posts: 1
Joined: 09 May 2012, 18:41

Re: Code Snippit worked in 4.1.5 doesn't work in 4.2

Postby sayontan » 09 May 2012, 19:14

lionscience wrote:adding it in the site breaks.

Breaks how?

One likely error with your code is that category__in is supposed to take an array parameter, but you are passing a string to it.
Sayontan Sinha | http://mynethome.net/blog | http://www.aquoid.com/news
I don't do freelance work (for Suffusion or otherwise), so please don't contact me for quotes or offers.
sayontan
Site Admin
 
Posts: 10159
Joined: 15 Sep 2009, 16:39
Location: Houston, Texas


Return to Support Requests

Who is online

Users browsing this forum: Google [Bot], homyphascarry and 5 guests