0

I'm building a website in Wordpress and wish to have a list of catogories on a seperate page which acts as a filter for the isotope plugin. So far i've managed to get this working however i now need to remove the phrase "academia" from each category as this is can only be seen in the backend of wordpress but when trying to use str_replace it doesn't render any results.

Is anyone kind enough to some help? :)

link to website : http://www.bluemoontesting.co.uk/intbauwp/testing/#

<?php

    $terms = get_categories('orderby=name&depth=1&title_li=&use_desc_for_title=1&parent=34');  // get all categories, but you can use any taxonomy
    $remove = str_replace("academia","", $terms);
    $count = count($remove); //How many are they?


    if ( $count > 0 ) {  //If there are more than 0 terms

        foreach ( $terms as $term ) 

        {  //for each term:
            echo "<li><a href='#' data-option-value='.".$term->slug."'>" . $term->name . "</a></li>\n";
            //create a list item with the current term slug for sorting, and name for label
        }
    }
?>
1

2 Answers 2

1

Add str_replace in foreach.

$name = str_replace("academia","", $term->name);

Like this :

if ( $count > 0 ) {
    foreach ( $terms as $term ) {
        $name = str_replace("academia","", $term->name);
        echo "<li><a href='#' data-option-value='.".$term->slug."'>" . $name . "</a></li>\n";
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the rapid responses! I tried adding your code hors sujet but it's now displaying a blank page? Please see bluemoontesting.co.uk/intbauwp/testing/#
the str_ireplace() function would still be better incase someone entered it with any UPPERCASE letters. That way they would still be picked up, but your method should work fine if UPPERCASE letters are not going to be an issue.
Case insensitive str_replace would be of better use in this scenario
0

You should echo out $terms and make sure it contains "academia". Your code should work as is without a for loop as the string isn't an array. My guess is that $terms may not contain the string you're looking for.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.