ACF custom post feed by custom taxonomy

I’m using wordpress with custom post type UI plugin and ACF plugin.
Trying to build a “single” template with multiple feeds of custom post types by custom custom taxonomy. Using this code, with a few variations to figure out what am i doing wrong.

Got 2 pieces of code like this in a row

Read More
<?php if( get_field('collectiona') ): 
    $argsc = array(
      'post_type' => 'products',
      'product-collections' => get_field('collectiona'),
    );
    $prods2 = new WP_Query( $argsc );
    if( $prods2->have_posts() ) {
      while( $prods2->have_posts() ) {
        $prods2->the_post();
        ?> 
       Whatever post code
      <?php
      }
    }
    else {
      echo '';
    }
  ?>
<?php endif; ?>

collectiona is a taxonomy field. With the piece of code, shown above, it just shows all the “products” posts out there. I’ve also tried using a text field with taxonomy slug. It shows first feed perfectly fine, if i’m not using first if statement (<?php if( get_field(‘collectiona’) ): ?>), and if that statement is present- same thing happens. All the “products” are shown. However, even with first feed shown fine, 2nd feed still shows all the “products” out there. Despite what taxonomy slug says.

I’m trying to build it the way, admin could chose a dropdown taxonomy. Text field with taxonomy slug is just an example.
p.s.
I use term object
Full template code is here jsfiddle.net/pudfbxhv . I know jsfiddle is useless for wp templates, but that’s a pretty big piece of code

EDIT

Here is updated code

<?php
            $taxterms = get_field("collectiona"); ?>                

                <?php
                $args = array(
                    'post_type' => 'products',
                    'tax_query' => array(
                        array(
                            'taxonomy' => 'product-collections',
                            'field' => 'id',
                            'terms' => $taxterm->term_id
                        )
                    )
                );

                $myquery = new WP_Query( $args );
                if($myquery->have_posts()) : ?>

                    <ul>
                        <?php while ( $myquery->have_posts() ) : $myquery->the_post(); ?>
                            <li> <a href="<?php the_permalink(); ?>"><img src="<?php the_field('prod_featured_image'); ?>" onmouseover="this.src='<?php the_field('prod_hover_featured_image'); ?>'" onmouseout="this.src='<?php the_field('prod_featured_image'); ?>'" /></a>
                                                             <h2><?php the_field('prod_subtitle'); ?></h2>
                                                             <p>$<?php the_field('prod_price'); ?></p>
                                                            </li>
                        <?php endwhile; ?>
                    </ul>
                <?php endif; ?>
                <?php wp_reset_query(); ?>

Related posts

1 comment

  1. Well, that may be a perversion, but it worked for me.

    $termss = get_field('collectiona');
        $slll = $termss->slug;
        $args = array(
          'post_type' => 'products',
          'product-collections' => $slll,
        );
        $lineblocks = new WP_Query( $args );
        if( $lineblocks->have_posts() ) {
          while( $lineblocks->have_posts() ) {
            $lineblocks->the_post();
    

    Also, gotta remember to put the following code after every array

    <?php wp_reset_query(); ?> 
    

Comments are closed.