Tell us what you are trying to do?
I'm trying to create a list of posts ordered by year and month as outlined in this post: https://toolset.com/2013/10/how-to-group-views-results-by-year-and-month/ - however, I would like the posts ordered by date-field and not post-date.
How would I alter the above instructions to group views by month and year from the date-field?
Is there any documentation that you are following?
https://toolset.com/2013/10/how-to-group-views-results-by-year-and-month/
Is there a similar example that we can see?
What is the link to your site?
Site is under development
Regards,
Del Morgan
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Well - you should use the same shortcode without any change and add it to your current theme's functions.php file:
add_shortcode('heading', 'my_heading');
function my_heading($atts, $content = '') {
static $year = null;
static $month = null;
$condition = $atts['condition'];
$value = $atts['value'];
switch ($condition) {
case 'year':
case 'month':
if ($$condition != $value) {
$$condition = $value;
return $content;
}
break;
}
return '';
}
And here is how you should call the shortcode within your view's loop:
<wpv-loop>
[heading condition="year" value="[types field='stud-registration-date' style='text' format='Y'][/types]"]
<h4>[types field='stud-registration-date' style='text' format='Y'][/types]</h4>
[/heading]
[heading condition="month" value="[types field='stud-registration-date' style='text' format='F'][/types]"]
<h5>[types field='stud-registration-date' style='text' format='F'][/types]</h5>
[/heading]
<li> <h4>[wpv-post-title]</h4> </li>
</wpv-loop>
Where:
- The only change is we are passing the custom date field instead of post date field.
- Please change the field name stud-registration-date with your original field name.
Thanks Minesh, that worked.
I modified it to display posts by "day" as well, though this produces the date number without the month before each date number.
This is what happens:
==
2018
AUGUST
6
sample text
sample text
7
sample text
8
sample text
sample text
==
However, I want the month to repeat with each day, eg:
==
AUGUST 2018
August 6
sample text
sample text
August 7
sample text
August 8
sample text
sample text
==
Assuming this is possible, how would I achieve this, so that the month displays with each new date grouping?
Thanks
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Well - I used following code in view's loop - no change in code you added to functions.php file:
<wpv-loop>
[heading condition="year" value="[types field='stud-registration-date' style='text' format='F'][/types] [types field='stud-registration-date' style='text' format='Y'][/types]"]
<h4>[types field='stud-registration-date' style='text' format='F'][/types] [types field='stud-registration-date' style='text' format='Y'][/types]</h4>
[/heading]
[heading condition="month" value="[types field='stud-registration-date' style='text' format='F'][/types] [types field='stud-registration-date' style='text' format='j'][/types]"]
<h5>[types field='stud-registration-date' style='text' format='F'][/types] [types field='stud-registration-date' style='text' format='j'][/types]</h5>
[/heading]
<li> <h4>[wpv-post-title]</h4> </li>
</wpv-loop>
Where:
- Please change the field name stud-registration-date with your original field name.
I see its working. Could you please confirm 🙂