Support

Account

Home Forums Add-ons Repeater Field Term doesnt work in WP_Query in repeater / options

Solved

Term doesnt work in WP_Query in repeater / options

  • Hi,

    I am trying to limit custom taxonomy posts from chosen category, but I am having trouble with it. Usually it works without any problems, all I do is WP_Query with settings like this:

    $serviceArgs = array(
    									'post_type' => 'services',
    									'taxonomy' => 'kategorie_uslug',
    									'term' => 'someCatname',
    									'post_status' => 'publish',
    									'posts_per_page' => -1,
    									'orderby' => 'title',
    									'order' => 'ASC'
    								);
    

    For some reason It doesn’t work in repeater loop from acf options. All I can do is list all posts (once I comment out term parameter in WP_Query), once I set term either with variable or fixed name, i get no results.

    Can you please check, where do I made an error ?

    <?php
    //Początek pętli menu kategorii - zmienna ikona.
    if( have_rows('ikona', 'option') ):
    	$n = 0;
    	while ( have_rows('ikona', 'option') ) : the_row(); ?>
    		<div role="tabpanel" class="tab-pane fade in <?php if($n == 0): ?>active<?php endif; ?>" id="service1level-<?php echo $n; ?>">
    			<ul class="nav nav-tabsServices2" role="tablist">
    			<?php 
    				if( have_rows('ikona_podkategorii', 'option') ):
    					$i = 0;
    					while ( have_rows('ikona_podkategorii', 'option') ) : the_row();
    						$ikonaPodKategoria = get_sub_field('podkategorii', 'option');
    						?>
    						<li role="presentation" <?php if($i == 0): ?> class="active" <?php endif; ?>> 
    							<a href="#service2level-<?php echo $i; ?>-<?php echo $n; ?>" aria-controls="service2level-<?php echo $i; ?>-<?php echo $n; ?>" role="tab" data-toggle="tab">
    								<h2><?php echo $ikonaPodKategoria[0]->name; ?></h2>
    								<?php echo $ikonaPodKategoria[0]->description; ?>
    
    							</a>
    						</li>
    					<?php $i++; ?>
    					<?php
    					endwhile;
    				endif;
    			?>
    			</ul>
    			<div id="catNavigationLevel3" class="tab-content">
    				<?php
    				if( have_rows('ikona_podkategorii', 'option') ):
    				$i = 0;
    					while ( have_rows('ikona_podkategorii', 'option') ) : the_row(); ?>
    						<?php 
    						$catName = get_sub_field('podkategorii', 'option');
    						$catSlug = $catName[0]->slug;
    						?>
    						<div role="tabpanel" class="tab-pane fade in <?php if($i == 0): ?>active<?php endif; ?>" id="service2level-<?php echo $i; ?>-<?php echo $n; ?>">
    							lista usług-<?php echo $i; ?>
    
    							<?php
    							/* Główna pętla */
    								$serviceArgs = array(
    									'post_type' => 'uslugi',
    									'taxonomy' => 'kategorie_uslug',
    									'term' => $catSlug,
    									'post_status' => 'publish',
    									'posts_per_page' => -1,
    									'orderby' => 'title',
    									'order' => 'ASC'
    								);
    							?>
    							<?php echo $catSlug; ?>
    
    							<div class="categoriesWrappInner row">
    								<?php 
    								$serviceLoop = new WP_Query($serviceArgs);
    								//print_r($serviceLoop);
    								//print_r($catName);
    								if($serviceLoop->have_posts()): 
    									while($serviceLoop->have_posts()): $serviceLoop->the_post(); 
    									?>
    										<div class="catElement col-xs-6 col-sm-3 col-md-2">
    											<div class="catElementInner">
    												<div class="catElementBody">
    													<h3 class="catTitle">
    														<?php the_title(); ?>
    													</h3>
    												</div>
    												<a class="btn btn-primary" href="<?php echo the_permalink(); ?>">więcej</a>
    											</div>
    										</div>
    									<?php endwhile; ?>
    									<?php wp_reset_postdata() ;?>
    								<?php else : ?>
    									<div class="col-xs-12 noPageFound">
    										<h2 class="title">Brak usług w wybranej kategorii</h2>
    									</div>
    								<?php endif; ?>
    							</div>
    						</div>
    				<?php $i++; ?>	
    				<?php
    					endwhile;
    				endif;
    				?>
    			</div>
    		</div>
    	<?php $n++; ?>	
    	<?php endwhile; ?>
    <?php endif; ?>
    
  • Found solution. Topic closed.

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

You must be logged in to reply to this topic.