Support

Account

Home Forums Front-end Issues Show Custom Taxonomy as Headline for related posts

Unread

Show Custom Taxonomy as Headline for related posts

  • Hi,
    I have a post with related posts. I do the relation with the Advanced Custom Fields Plugin. It works that I can show all the related posts of the term, but in addition I want to show only the name of the term as headline. Unfortunately that doesn’t work.
    This is my code:

    $post_objects = get_field('team1');
    
                                if( $post_objects ): ?>
    
                                <?php //echo '<h3>'.get_terms('tshowcase-taxonomy', 'slug='.get_query_var('tshowcase-taxonomy')).'</h3>' ?>
    
    <!--                                get related members-->
                                    <?php
                                        $custom_terms = get_terms('tshowcase-taxonomy');
                                         echo '<h3>Research by</h3>';
    
                                    //get Assistance
                                    $post = $post_objects; // variable must be called $post (IMPORTANT)
                                    setup_postdata($post);
                                    if(!empty(is_object_in_term($post->ID, 'tshowcase-taxonomy',Assistence))) {
                                        //if ($loop->have_posts()) {
    
                                        echo '<h4><i>' . Assistence . '</i></h4>';
    
                                    }else{
                                        echo 'nichts';
                                    }
                                        //endforeach;
                                    /*    while($loop->have_posts()) : $loop->the_post();
                                            echo '<a href="'.get_permalink().'">'.get_the_title().'</a><br>';
                                        endwhile;*/
                                    //wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
    
                                        foreach ($post_objects as $post): // variable must be called $post (IMPORTANT)
                                            setup_postdata($post);
                                            if (is_object_in_term($post->ID, 'tshowcase-taxonomy', Assistence)) {
    
                                                if (has_post_thumbnail()) {
                                                    echo '<a href="' . get_permalink() . '">' . get_the_title() . "<br>" . get_the_post_thumbnail($postid, array(150, 150), array()) .  '</a><br>';
                                                } else {
                                                    echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a><br>';
                                                }
                                                }
                                        endforeach;
                                        echo '<br>';
                                        /*    while($loop->have_posts()) : $loop->the_post();
                                                echo '<a href="'.get_permalink().'">'.get_the_title().'</a><br>';
                                            endwhile;*/
                                        wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
                                 //}

    The loop, which show all related posts, works. But the upper code, to show only the headline shows also a headline, if there is no related post with this term. Someone knows a solution for this problem? Thanks a lot!

Viewing 1 post (of 1 total)

The topic ‘Show Custom Taxonomy as Headline for related posts’ is closed to new replies.