Grow your CSS skills. Land your dream job.

help with WordPress loop

  • # September 17, 2012 at 11:32 pm

    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.

    # September 18, 2012 at 12:04 am

    @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 );
    ?>

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".