Home Forums Front-end Issues Taxonomy related posts.


Taxonomy related posts.

  • Hi, i want to show related posts in my custom post type with taxonomy automaticly.

  • Can you explain a bit more what you’re looking for?

  • i have a custom post type which “film” and they have custom taxonomies like genres “scary” “history” “drama” . When you enter a single-film.php i want in bottom some of 5 post which they also same taxonomies like “scary” or “history”

    I know we can make it in wordpress panel but i dont want to do it manually. I want automatic loop for that.

  • There isn’t anything in ACF that will automatically add what you’re looking for to the front of the site. I don’t even know of any plugins that will do this for you. You’ll need to code the queries and loops. If you’re looking for a plugin that will manage the fields and create the template without coding there are other plugins that will do that. As a user I see ACF as a tool for coders.

  • This reply has been marked as private.
  • Sine you’re a coder I won;y go into coding and I’ll just give you the outline.

    The first thing you need to do is to get the terms for the current post The first thing you need to do is to get the terms for the current post.

    Next you do a new WP_Query, including a tax_query to get other posts that are in the same term

    and finally you loop through the returned posts, if any, to show the list.

    Let me know if you need help any of the code that goes with these steps.

  • This reply has been marked as private.
      $selected = get_field('turler');
      $args = array(
        'post_type' => 'film',
        'tax_query' => array(
            'taxonomy' => 'tur',
            'field' => 'slug',
            // the default operatre is "IN"
            // there is no == operator for tax_query
            // see
            'terms' => array($selected),
      $angebot_2 = new WP_Query( $args );
      while( $angebot_2->have_posts() ) : $angebot_2->the_post();
      <?php the_title(); ?>
      <?php endwhile; wp_reset_postdata(); ?>
  • So i cannot loop posts with same taxonomy ha ???

  • You asked what you’re problem was with the query you had. I commented the error that I saw. I’m not sure what you’re looking for.

    if this returns the term in the taxonomy of the current post
    $selected = get_field('turler');
    then the query will display all of the posts in the same term.

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Taxonomy related posts.’ is closed to new replies.