| Server IP : 51.91.236.255 / Your IP : 216.73.216.180 Web Server : Apache System : Linux webm017.cluster129.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : laureet ( 1012854) PHP Version : 8.0.30 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/laureet/www/wp-content/themes/rhye/inc/functions/helpers/ |
Upload File : |
<?php
if ( ! function_exists( 'arts_get_post_looped' ) ) {
function arts_get_post_looped( $args ) {
$defaults = array(
'loop' => true,
'direction' => 'backward',
'in_same_term' => false,
'excluded_terms' => '',
'taxonomy' => 'category',
);
$args = wp_parse_args( $args, $defaults );
$is_previous = $args['direction'] === 'forward';
$post = get_adjacent_post( $args['in_same_term'], $args['excluded_terms'], $is_previous, $args['taxonomy'] );
if ( $post ) {
return $post;
} elseif ( ! $args['loop'] ) {
return null;
} else {
$posts = array();
$query_args = array(
'post_type' => get_post_type(),
'posts_per_page' => -1,
'no_found_rows' => true,
);
// filter next/prev post by the same term
if ( $args['in_same_term'] ) {
$terms = array();
$current_terms = arts_get_taxonomy_term_names( get_the_ID(), $args['taxonomy'] );
if ( ! empty( $current_terms ) ) {
foreach ( $current_terms as $term ) {
array_push( $terms, $term['slug'] );
}
$query_args['tax_query'] = array(
array(
'taxonomy' => $args['taxonomy'],
'field' => 'slug',
'terms' => $terms, // include only posts of the current terms (slugs)
),
);
}
}
$loop = new WP_Query( $query_args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) {
$loop->the_post();
$posts[] = get_post();
}
wp_reset_query();
}
if ( ! empty( $posts ) ) {
if ( $is_previous ) {
return $posts[0];
} else {
return $posts[ count( $posts ) - 1 ];
}
}
}
}
}