I am trying to group a list by a post reference field, similar to what we achieved here: https://toolset.com/forums/topic/view-of-upcoming-events-but-w-dates-distance-from-2-related-child-post-types/#post-1126170
It works fine if I group by a parent field in a post relationship. But it does not work if I'm trying to do the same but using a post reference field instead.
Here's the code I have in the view template loop for now:
[group-title condition="title" value="[wpv-post-title item='@race_event.parent']"]
<li>[wpv-post-title item="@race_event.parent"]</li>
[/group-title]
The function for the [group-title] shortcode looks like this:
add_shortcode('group-title', 'func_group_by_display_title');
function func_group_by_display_title($atts, $content = '') {
static $title = null;
$condition = $atts['condition'];
$value = $atts['value'];
switch ($condition) {
case 'title':
if ($$condition != $value) {
$$condition = $value;
return $content;
}
break;
}
return '';
}
From counting the number of list items it does seems that it groups by the same Post Reference fields. But the actual values of the Post Reference field are not output... If I remove the shortcode it outputs a list of all the fields with the post title from the Post Reference field. But when I add the shortcode, nothing.
Can I not use a post reference field in such a way or do I have to do it differently?
I'm working with the view called "Test", with output on this page: hidden link
Hi, I updated the shortcode a bit for you to compare based on the post reference field value, which is a numeric ID. Here's the updated code:
[group-title condition="title" value="[wpv-post-field name='wpcf-race_event']"]
<li>[wpv-post-title id="[wpv-post-field name='wpcf-race_event']"]</li>
[/group-title]
Can you check to confirm it's grouping as expected?
Perfect! That works great.