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.

This question is an exact duplicate of:

I am trying to make a function but (because the lack of my knowledge) can't figur out how to do.

The codex shows an example for using 1 taxonomy and 1 term and as output nice showing 1 Taxonomy / 1 Term without hyperlink (which is what I want to achieve but then with multiple taxonomies/terms) in one function.
At that point I am totally stucked, also tried wp_get_post_terms() but there probably must be used an array, and there mylack of knowledge hops in again :(

I can't find anywhere a sample, not in the codex, not through google neither here on stackexchange. Maybe I did not search well enough, if so then I want to apologize but still look for an answer/help.

Below a sample which absolutly not is working but giving at least an idea about what I want to achieve. Result is not showing an error? The "article" information is overwriting the school information and the last (teacher) information the "article" information.

function my_function($content) {
if ( is_single() && in_category( '5' ) ) {

    global $post, $school, $article, $teacher;

        $terms = get_the_terms ($post->ID, 'school');
        $terms = get_the_terms ($post->ID, 'article');
        $terms = get_the_terms ($post->ID, 'teacher');

    if ( $terms && ! is_wp_error( $terms ) ) :
        $school_links = array() && $article_links = array() && $teacher_links = array() ;

        foreach ( $terms as $term ) {
            $school_links[] = $term->name & $article_links[] = $term->name & $teacher_links[] = $term->name;

        }

        $school = join( ", ", $school_links ) & $article = join( ", ", $article_links )  & $teacher = join( ", ", $teacher_links ) ;

?>
<div style="margin:40px;">  
<?php the_post_thumbnail('thumbnail', array('class' => 'top-post-img' )); ?>
School: <strong><?php echo $school; ?></strong><br />
Article: <strong><?php echo $article; ?></strong><br />
Teacher: <strong><?php echo $teacher; ?></strong>
</div>
<?php       
    endif;
    return $content;
} else { 
    return $content;
    }
}
add_filter('the_content', 'my_function'); 

Appreciate all time/effort and help to find an answer.

Note:
I am absolutely not a coder just know how to us google :D

share|improve this question
1  
What exactly are you trying to accomplish? –  Andrew Bartel Dec 18 '13 at 18:12
    
@Andrew, input will be done in back-end and shown on top of that posting in that specific catogory, as tried to show in the sample. So how am I able to do such, because the one above is without the clickable hyperlinks. The other way is easy..echo output and done, but then the links are clickable and that is not my goal. Above works with 1 tax and term very simple already done that (see codex sample) so it should also be doable with multiple taxonomies and terms and thats where I am stuck –  Charles Dec 18 '13 at 19:36
add comment

marked as duplicate by Rarst Dec 21 '13 at 15:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

I had a totally wrong approach as I found out, needed to use wp_get_post_terms and had to use arrays.
Because I am absolutely not a coder I had to dig into codex and this came out and seems to work, flawless?

If this answer could trigger some nasty or the code could/should be better please don't hasitate to comment or to correct my answer.

function my_function($content) {
    if ( is_single() && in_category( '5' ) ) {     
    the_post_thumbnail('thumbnail', array('class' => 'top-post-img' ));    
global $post;
$term_list=wp_get_post_terms($post->ID,array('school','article','teacher'),array("fields" => "names"));
?>
<div style="margin:45px;">
    School: <strong><?php print_r($term_list[0]); ?></strong><br />
    Article: <strong><?php print_r($term_list[1]); ?></strong><br />
    Teacher: <strong><?php print_r($term_list[2]); ?></strong>
</div>
<?php       
return $content;
} else { 
return $content;
}
}

add_filter('the_content', 'my_function');

Output is as wanted, debug shows no errors and hoping now that I did not make a mistake.

Edit:
Sample (not arbitrarily)?
Found out that results are alphabetical arghhh, some like this array ('orderby' => '??? ' ) should solve that problem. Does anyone know what should be on the questionmarks?

share|improve this answer
add comment

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