Skip to content

Instantly share code, notes, and snippets.

@mi-ca
Last active August 22, 2020 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mi-ca/71bfbef536ffa73226e86ce0c299a50f to your computer and use it in GitHub Desktop.
Save mi-ca/71bfbef536ffa73226e86ce0c299a50f to your computer and use it in GitHub Desktop.
meta_query acf dates repeater field (related futures events)
<?php
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'dates_$", "meta_key LIKE 'dates_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
function getRelatedEvents($id,$taxonomies){
$today = date('Ymd');
$tlist=[];
$meta_query = array('relation' => 'OR');
// construction de la requête car wpquery n'accèpte pas les tableaux
foreach ($taxonomies as $key=>$v) {
$tlist[]=$key;
$meta_query[] = array(
'key' => 'categories',
'value' => '"' . $key . '"',
'compare' => 'LIKE'
);
}
$args=array(
'post_type' => 'evenements'
,'meta_key' => 'dates_$_date_fin'
,'orderby' => 'meta_value_num'
,'order' => 'ASC'
,'post__not_in' => array($id)
,'posts_per_page'=> 3
,'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'dates_$_date_fin',
'compare' => '>=',
'value' => $today,
),
$meta_query
)
);
$d='';
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
// Do Stuff
endwhile;
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment