Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am having issues with the get_the_terms php that is pulling in my current posts categories (custom taxonomy portfolio_category). I can successfully pull in the last category.

If you look at this page you'll see links along the top: http://www.slarc.com/portfolio-view/central-control-building-east-texas/ those links are pulled in via get_the_ters_list but the links don't have: www. slarc. com / projects in front of it. Where I need it to jump to a page with the same slug. That's why I started working with the code below. It works, but it only pulls in ONE taxonomy? This is the second line of links on the page: http://www.slarc.com/portfolio-view/central-control-building-east-texas/

PHP Code: ID, 'portfolio_category' );

                if ( $terms && ! is_wp_error( $terms ) ) : 

            $portfolio = array();

            foreach ( $terms as $term ) {
                $portfolio[] = $term->name;
            }

            $portfolio_category = join( " | ", $portfolio );
        ?>

            <h3 id="Proj_Categories"><ul>
                <?php echo '<a href="http://www.slarc.com/projects/'.$term->slug.'">'.$term->name.'</a>'; ?>
            </ul></h3>

        <?php endif; ?>

How can I pull in all the taxonomies??

FYI-Ignore the links on top that show up. These are brough in with the get_the_terms_list

But those need the http:// www. slarc.com/ projects in front of the links.

Thanks, Lorne

EDIT (GOT THE WORKING CODE Thanks jfacemyer!):

PHP Code: ID, 'portfolio_category' );

                if ( $terms && ! is_wp_error( $terms ) ) : 

            $portfolio = array();

            foreach ( $terms as $term ) {
                $portfolio[] = $term->name;
            }

            $portfolio_category = join( " | ", $portfolio );
        ?>

        <h3 id='Proj_Categories'>
        <?php
            $url = site_url();
                foreach ( $terms as $term ) {
                    $linklist .= "<li><a href='" . $url . "/projects/" . $term->slug . "'>" . $term->name . "</a></li>\n";
                }
            echo "<ul>" . $linklist . "</ul>";
        ?>
        </h3>

        <?php endif; ?>
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You need to include your html inside the foreach, something like this:

$url = site_url();
foreach ( $terms as $term ) {
    $linklist .= "<h3 id='Proj_Categories'><a href='" . $url . "/projects/" . $term->slug . "'>" . $term->name . "</a></h3>\n";
}
echo "<ul>" . $linklist . "</ul>";

(I haven't checked this code...)

It looks like you were trying to do something with making an array of the links, maybe, joined by pipes as separators? If so, make your array with the the terms, then do another foreach with that array and create the links.

Looks like you were only getting one of the terms because you were calling $term (not sure where that was set, outside of the first loop) rather than looping through the array of terms.

share|improve this answer
    
AWESOME!! This worked great! Thanks so much for your help! I added my final code above... –  lorne17 Mar 5 '13 at 15:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.