0

I am trying to solve a problem for last two weeks but still I haven’t not found any solution yet.
Let me explain my problem first:
I have two custom post types: one is football_fixture and second is football_league.
These two CPT have two common taxonomies: one is “competition” and second is ‘’session”.These two taxonomies have terms also; for example: laliga, EPL, Seria and 2016-17, 2015-16 respectively.
Now what I want :
In my football_league post , I want to show the content of football_fixture according to following condition:
1)In football_league post If I select term of competition taxonomy and session taxonomy then it will show only the content of football_fixture posts which has those terms. See image for more explanation: enter image description here Suppose, I have published 5 football_fixture posts with competition terms “laliga” and session term “2026-17”.
Now if I published a football_league post with competition terms “laliga” and session term “2026-17” then it will show those 5 football_fixture’s 5 post. Is it possible? I used following codes:

0

I have solved the problem myself:
What I did is:
First created single-football_league.php template where i placed following codes:

<?php while ( have_posts() ) : the_post(); ?>
                    <?php get_template_part( 'content-parts/content', 'league' ); ?>
                <?php endwhile; ?> 

Second: In content-league.php, I placed following codes, and it works:

$terms = wp_get_post_terms( $post->ID, array('competition', 'session') );
$term_slugs = wp_list_pluck( $terms, 'slug' );    
 $season = wp_get_post_terms( $post->ID, 'session' );
$season_slugs = wp_list_pluck( $terms, 'slug' ); 
$args = array(
        'post_type' => array( 'football_fixture' ), // profile and letter are CPTs
            'tax_query' => array(
                array(
                'taxonomy' => 'competition',
                'field' => 'slug',
                'terms' => $term_slugs
                ),
               array (
              'taxonomy' => 'session',
              'terms' => $season_slugs,
              'field' => 'slug')
            )   
    );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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