So, I have a couple custom fields using ACF. On them I have a field called cd_location (group -> repeater -> select).
I've made a page template (based on my custom working archive) that should return ALL the courses that contain the location Y (GET / xxx.com/?loc=YYY) but it's not working at all and I don't know why. Can someone advise please?
Based on Dynamic $_GET parameters.
My top php code:
global $post;
global $_GET;
$heading = get_field( 'heading', $post->ID );
$course_dates = get_field('course_dates', $post->ID);
Then I have the loop:
<?php
if ( have_posts() ) :
$counter = 0;
while ( have_posts() ) : the_post(); ?>
<div class="one_half<?php echo ( ++$counter == 2 ) ? ' last_column' : ''; ?>">
<div class="break-link">
<?php
get_portfolio_item_thumbnail( $post->ID, '5', '528', '328', true );
?>
</div>
<h4 class="cont-subtitles"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<p class="excerpt"><?php echo excerpt(15); ?></p>
</div><!-- end one_half -->
<?php if ( $counter == 2 ) : ?>
<div class='clear'> </div>
<?php $counter = 0;
endif;
endwhile;
endif; ?>
This on functions.php:
add_action( 'pre_get_posts', function( $query ) {
if ( isset( $query->query_vars[ 'post_type' ] ) && $query->query_vars[ 'post_type' ] == 'e-kursus' && isset( $_GET[ 'loc' ] ) ) {
$query->set( 'meta_key', 'cd_location' );
$query->set( 'meta_value', sanitize_text_field( $_GET[ 'loc' ] ) );
}
return $query;
} );
It's returning a dummy post with the name of the page with no fields from ACF