treehouse : what would you like to learn today?
Web Design Web Development iOS Development

help with WordPress loop

  • I am trying to exclude categories from the WordPress loop. I have an admin area that has a text box that you can enter the category slugs that you want to exclude. I am having the hardest time trying to figure this out. I am using the SMOF framework. A simple input box that returns a string. So when I echo out my test, I can get

    homepage recent-news

    I tried a foreach loop to get the category id but it isn't working. I keep running into php errors. I have been trying to use the get_category_id_by_slug() function and I can't even get it tested. Right now I tried the simplest test like so

    
    $slug = 'homepage';
    $category_id = get_category_id_by_slug( $slug );
    echo $category_id;
    

    This returns an error saying this Object of class stdClass could not be converted to string

    It shouldn't need to be converted to a string because it already is one.

  • @cybershot I'm not sure what you're trying to do exactly but your code shows that you want to echo out a category of 'homepage'. However, I don't believe that is a valid function but get_category_by_slug is. Try the following:

      <?php 
      $cat_id = get_category_by_slug('homepage');
      echo get_cat_name( $cat_id );
      ?>