0

I am very new to coding.The following code is working fine which shows the post which has taxonomy "persons", but when I am using second part then it is not showing the content.What I want is to show the post which has the person and animal taxonomy terms.

   $terms = wp_get_post_terms( $post->ID, 'persons' );
$term_slugs = wp_list_pluck( $terms, 'slug' );

'tax_query' => array(
     array(
         'taxonomy' => 'persons',
         'field' => 'id',
         'terms' => $term_slugs
         )
     ),

Second part:

$terms = wp_get_post_terms( $post->ID, 'persons' );
  $term_slugs = wp_list_pluck( $terms, 'slug' );
$terms2 = wp_get_post_terms( $post->ID, 'animal' );
  $term_slugs2 = wp_list_pluck( $terms, 'slug' );

    'tax_query' => array(
         array(
             'taxonomy' => 'persons',
             'field' => 'id',
             'terms' => $term_slugs
             ),
           array(
             'taxonomy' => 'animal',
             'field' => 'id',
             'terms' => $term_slugs2
             )
         ),
  • Is that code as is, or are you leaving parts out to make your question shorter? I don't see the call to WP_Query, and if you were to use that code as is, you'd get syntax errors and a server 500 response as that isn't valid PHP – Tom J Nowell Oct 9 '16 at 18:30
  • yes, I am leaving. – attoma Oct 9 '16 at 18:39
  • 2
    I'm not sure I understand, yes it's as is, or yes there's parts missing?Can you edit your question so that it contains the relevant code? It could be your post loop at fault, or other options in your query – Tom J Nowell Oct 9 '16 at 18:52
0

Use this code instead.

$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')
            )   
    );


    $my_query = new WP_Query($args);

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.