Итак, у меня есть пара пользовательских полей, использующих ACF. На них у меня есть поле с именем cd_location (группа -> повторитель -> выбрать).
Я создал шаблон страницы (на основе моего собственного рабочего архива), который должен возвращать ВСЕ курсы, содержащие местоположение Y (GET / xxx.com/?loc=YYY), но он не работает вообще, и я не не знаю почему. Может кто-нибудь посоветовать, пожалуйста?
На основе Динамических параметров $ _GET .
Мой топ php код:
global $post;
global $_GET;
$heading = get_field( 'heading', $post->ID );
$course_dates = get_field('course_dates', $post->ID);
Тогда у меня есть цикл:
<?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; ?>
Это на 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;
} );
Возвращает фиктивный пост с названием страницы без полей из ACF