is_home() && $query->is_main_query() ) {
$query->set( 'cat', '2');
if ( !empty( $_GET['person'] ) ) {
$query->set( 'meta_query', array(
array(
'key' => 'mitreisende',
'value' => $_GET['person'],
'compare' => 'LIKE'
)
) );
}
}
}
add_action( 'pre_get_posts', 'my_home_category' );
// Related posts function
function atravelblog_related_posts() {
global $post;
$thisID = get_the_ID();
$cat = get_the_category()[0]->name;
if ( $cat == 'Urlaub' ){
$tagebuch = new WP_Query( array(
'category_name' => 'Tagebuch',
'posts_per_page' => -1,
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'urlaub', // name of custom field
'value' => '"'.get_the_ID().'"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
) );
if ($tagebuch->have_posts()) :
echo('
Tagebuch Einträge:
');
echo('');
while ( $tagebuch->have_posts() ) : $tagebuch->the_post();
global $post;
get_template_part( 'content', get_post_format() );
endwhile;
echo('
');
echo('
');
endif;
wp_reset_query();
$album = new WP_Query( array(
'category_name' => 'Album',
'posts_per_page' => -1,
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'urlaub', // name of custom field
'value' => '"'.get_the_ID().'"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
) );
if ($album->have_posts()) :
echo('Fotoalben:
');
echo('');
while ( $album->have_posts() ) : $album->the_post();
global $post;
get_template_part( 'content', get_post_format() );
endwhile;
echo('
');
echo('
');
endif;
wp_reset_query();
$touren = new WP_Query( array(
'category_name' => 'Tour',
'posts_per_page' => -1,
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'urlaub', // name of custom field
'value' => '"'.get_the_ID().'"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
) );
if ($touren->have_posts()) :
echo('Touren:
');
echo('');
while ( $touren->have_posts() ) : $touren->the_post();
global $post;
get_template_part( 'content', get_post_format() );
endwhile;
echo('
');
echo('
');
endif;
wp_reset_query();
} elseif($cat == 'Tour' || $cat == 'Album' || $cat == 'Tagebuch') {
$urlaub = new WP_Query(array('p' => get_field('urlaub')[0]));
if ($urlaub->have_posts()) :
echo('Urlaub:
');
echo('');
while ( $urlaub->have_posts() ) : $urlaub->the_post();
global $post;
get_template_part( 'content', get_post_format() );
endwhile;
echo('
');
echo('
');
endif;
wp_reset_query();
}
}