PHP error Exclude post categories from loop
-
Hi, unsure if correct forum but here goes.
I have an installation with Buddy theme installed with buddypress. I want to exclude a category of post from the loop and found this code at http://wpsites.net/web-design/exclude-category-posts-page/
add_action( ‘pre_get_posts’, ‘exclude_category_posts’ );
/**
* @author Brad Dalton – WP Sites
* @example http://wpsites.net/web-design/exclude-category-posts-page/
*/
function exclude_category_posts( $query ) {
if( $query->is_main_query() && $query->is_home() ) {
$query->set( ‘cat’, ‘-27,-30’ );
}
}When I put this in my functions.php in my child theme, the admin outputs this error:
Warning: Cannot modify header information – headers already sent by (output started at /home/mysite/public_html/wp-content/themes/buddy-child/functions.php:37) in /home/mysite/public_html/wp-admin/post.php on line 242
Warning: Cannot modify header information – headers already sent by (output started at /home/mysite/public_html/wp-content/themes/buddy-child/functions.php:37) in /home/mysite/public_html/wp-includes/pluggable.php on line 1207
The frontend is not affected, but shows the category ID I want to exclude.
Can anyone please help me find out what the problem is?
Terjemk
- The topic ‘PHP error Exclude post categories from loop’ is closed to new replies.