My site disappeared when trying to add a category to the php file

My website has disappeared completely with this message… I was adding category ’ -109’ to the functions exclude category below the error

I cannot get to the site or dashboard it is completely gone.even after removing the -109 category and updating the file to the original. -49

Siteground restored the site but why did this happen?? and how can I add category 109 to the 49 that is excluded? Siteground sent the file below, but I dont understand what that is for.

The functions.php that you edited can be found in /home/rendezv5/public_html/wp-content/themes/x-child/, named functions.php.old.

Hi There,

Thanks for writing in! Did you try a plugin to exclude category ? You can try a plugin like here (https://wordpress.org/plugins/ultimate-category-excluder/).

Hope that helps.

No, Themex Staff told me to use that code a few months ago and put into my php functions folder. I have Ethos 1 as my theme. they said to just add other categories to that code. Why did my site crash? How do I add another category to the original -49 without that happening again? Is YOUR recommendation to delete the original code and use the above plug-in??

Hi There,

Plugins are just alternative methods. If you have a specific requirement, you might have to add custom codes into your child theme.

Could you please post the whole code in your functions.php file, so that we can check your error.

Thanks!

this is everything in my file from the wp dashboard editor

<?php // ============================================================================= // FUNCTIONS.PHP // ----------------------------------------------------------------------------- // Overwrite or add your own custom functions to X in this file. // ============================================================================= // ============================================================================= // TABLE OF CONTENTS // ----------------------------------------------------------------------------- // 01. Enqueue Parent Stylesheet // 02. Additional Functions // ============================================================================= // Enqueue Parent Stylesheet // ============================================================================= add_filter( 'x_enqueue_parent_stylesheet', '__return_true' ); // Additional Functions // ============================================================================= function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-49' ); } } add_action( 'pre_get_posts', 'exclude_category' );

Hello There,

Are you trying to exclude more than one category? If that is the case, you will have to separate each of the category ID with a comma. You can make this code:

function exclude_category( $query ) {
  if ( $query->is_home() && $query->is_main_query() ) {
    $query->set( 'cat', '-49, -1,-2,-3' );
  }
}
add_action( 'pre_get_posts', 'exclude_category' );

Please let us know if this works out for you.

Thank you, now I see what happened, I put the ‘-49’, ‘-109’, marks at the wrong place and that was a fatal error, I guess!

Hey There,

You’re welcome. It’s good to know that this code helped you in resolving the issue.
If you need anything else we can help you with, don’t hesitate to open another thread.

Cheers.