I figured it out, this is resolved
$past_args = array(
'paged' => $paged,
'posts_per_page' => -1,
'post_type' => 'exhibition',
'meta_query' => array (
'relation' => 'AND',
array (
'key' => 'ex_start',
'value' => $today,
'compare' => '<',
'type' => 'DATE'
),
array(
'key' => 'ex_groupsolo', // name of custom field
'value' => 'group',
)
),
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
@codeview amazing what we copy paste coders can do these days 🙂
have a good one
@codeview muchas gracias! i have my own thing going now and it works,
I am now at the next step where i need to add a condition from a group switch to the mix (group/solo). I have the code, I just don’t know how to merge it in. Perhaps you have some advice.
Most grateful in any case
This is where I am at:
<?php if (have_posts()) : ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$today = date('Ymd');
$past_args = array(
'paged' => $paged,
'posts_per_page' => -1,
'post_type' => 'exhibition',
'meta_query' => array (
array (
'key' => 'ex_start',
'value' => $today,
'compare' => '<',
'type' => 'DATE'
)
),
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
query_posts( $past_args );
?>
<?php
echo '<div class="biotitle">' . 'Solo Exhibitions' . '</div>';
?>
<!-- PAST EXHIBITIONS -->
<?php while (have_posts()) : the_post(); ?>
<?php
$date = get_field('ex_start');
$gallery = get_field('ex_gallery_name');
$past_year = DateTime::createFromFormat('Ymd', $date);
$year = $past_year->format('Y');
// get start date
$datum1 = get_field('ex_start', false, false);
// make start date object
$datum1 = new DateTime($datum1);
// get end date
$datum2= get_field('ex_end', false, false);
// make end date object
$datum2 = new DateTime($datum2);
if ($year !== $today) { ?>
<h2><?php echo $year; ?></h2><p><br /></p><p><br /></p>
<?php } ?>
<a href="<?php the_permalink(); ?>" class="exhibit"><?php the_title(); ?> , <?php echo $gallery; ?> , <?php echo $datum1->format('j M Y'); ?> - <?php echo $datum2->format('j M Y'); ?></a>
<?php $today = $year; ?>
<?php
echo "<p><br /></p>";
?>
<?php endwhile; ?>
<?php endif; ?>
and this is my final argument, that i am to inexperienced to merge in:
<?php
$posts = get_posts(array(
'meta_query' => array(
array(
'key' => 'ex_groupsolo', // name of custom field
'value' => 'solo',
)
)
));
if( $posts ) {
//...
}
?>
I have a solution now
this is the code if anyone needs it:
<?php if (have_posts()) : ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$today = date('Ymd');
$past_args = array(
'paged' => $paged,
'posts_per_page' => -1,
'post_type' => 'exhibition',
'meta_query' => array (
array (
'key' => 'ex_start',
'value' => $today,
'compare' => '<',
'type' => 'DATE'
)
),
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
query_posts( $past_args );
?>
<!-- PAST EXHIBITIONS -->
<?php while (have_posts()) : the_post(); ?>
<?php
$date = get_field('ex_start');
$past_year = DateTime::createFromFormat('Ymd', $date);
$year = $past_year->format('Y');
if ($year !== $today) { ?>
<h2><?php echo $year; ?></h2>
<?php } ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php $today = $year; ?>
<?php
echo "<p><br /></p>";
?>
<?php endwhile; ?>
<?php endif; ?>
Hi
I am waking up this post again because I am looking for the same thing, but with custom posts.
My post type is ‘exhibit’ and I have a date picker called ‘ex_start’
I need help to adapt Elliots fine code to list my fields by year with the year as title
thank you!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.