WordPress.org

Ready to get started?Download WordPress

Forums

Exclude a category from the loop (37 posts)

  1. johndove523
    Member
    Posted 1 year ago #

    Fatal error: [] operator not supported for strings in /home/content/J/D/a/JDatACAC/html/testing/wp-includes/query.php on line 1747

  2. cinghaman
    Member
    Posted 1 year ago #

    function cat_to_exclude($wp_query) {
      if ( !is_home() || !is_front_page() ) {
        $wp_query->set('category__not_in', '4');
      }
      return $query;
    }
    add_filter('pre_get_posts', 'cat_to_exclude');

    Can you replace the code again

  3. johndove523
    Member
    Posted 1 year ago #

    same result.

  4. cinghaman
    Member
    Posted 1 year ago #

    if ( !is_front_page() )
    just add this instead of
    if ( !is_home() || !is_front_page() )

  5. johndove523
    Member
    Posted 1 year ago #

    just to clarify, is this what you think it should be? :

    `function cat_to_exclude($wp_query) {
    if ( !is_front_page() ) {
    $wp_query->set('category__not_in', '4');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'cat_to_exclude');

  6. cinghaman
    Member
    Posted 1 year ago #

    yup- as such both it is working perfectly on my blog -not sure why it gives error on urs -+ fatal error is not even related to this

  7. johndove523
    Member
    Posted 1 year ago #

    Nope, same thing. Removes it from the blog, but crashes the home page.

    I really appreciate you giving me so much of your time, not sure why we're getting different results, but it's not that big a deal. THANK YOU! : )

Topic Closed

This topic has been closed to new replies.

About this Topic