Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End help with WordPress loop

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #27411
    cybershot
    Participant

    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.

    #110244
    chrisburton
    Participant

    @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:

    $cat_id = get_category_by_slug(‘homepage’);
    echo get_cat_name( $cat_id );
    ?>

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.