Support » Plugin: Pods - Custom Content Types and Fields » Related posts by custom taxonomy created with Pods

  • Resolved David

    (@davidki)


    Hi. I would be very grateful if you can help me. With Pods I created custom taxonomy “store” and I am trying to display related posts by custom taxonomy created with pods plugin. It means that on every post page I need to display related posts from the same taxonomy term like the current post.

    Author of my theme created some additional post taxonomy “dealstore”. I edited template for related post to dispaly related posts from this taxonomy “dealstore”. It works well. But when I try do the same for my custom taxonomy “store” created with Pods plugin, No related posts are displayed.

    Bellow is the beginning of code from my related post template which works well. But when I overwrite “dealstore” with my custom taxonomy “store” created with Pods plugin, it doesn’t work. Please, can you look at that code. What can I do to make it work with my custom taxonomy created with Pods?

    Thank you, David

    <?php if ( ! defined( ‘ABSPATH’ ) ) exit; // Exit if accessed directly ?>
    <?php

    $base_post = $post;
    global $post;
    foreach((get_the_terms($post->ID, ‘store’)) as $term) {
    $termID = $term->term_id;
    $args = array(
    ‘post_type’ => ‘post’,
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => 3,
    ‘orderby’ => ‘rand’,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘store’,
    ‘field’ => ‘id’,
    ‘terms’ => $termID
    )
    ),
    ‘post__not_in’ => array ($post->ID),
    );
    }
    $my_query = new wp_query( $args );
    if( $my_query->have_posts() ) { ?>
    <div class=”related_articles clearfix”>
    <div class=”related_title”>
    <h2>Deals</h2>
    </div>
    <?php while( $my_query->have_posts() ) {
    $my_query->the_post();?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jim True

    (@jimtrue)

    There’s no difference with a Custom Taxonomy created with Pods and a regular registered taxonomy. First question: is this taxonomy ‘store’ associated to the ‘post’ post-type? That’s being limited in your query specifically to post-type: post, so that would be a factor.

    And it looks like you only want to show posts that have some terms in ‘store’ that are the same as the current post. Are you getting any errors from your script? Have you turned on Debug in WordPress to see if your code is throwing any warnings? It’s also really hard to read your code since you didn’t enclose it in ‘code’ blocks to delineate it in the post above.

    Plugin Author Jim True

    (@jimtrue)

    @davidki Haven’t heard anything back from you on this one, so I’m guessing you’ve resolved the issue. If you haven’t please feel free to reply and re-open.

    Thanks!

    David

    (@davidki)

    Oh, sorry I forgot to response. I finally resolved my problem. Thank you very much for your time Jim.

    David

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Related posts by custom taxonomy created with Pods’ is closed to new replies.