i had to do it, i was looking for something very simple : just add a date event to some post to show it in archive of my news (it can be a start date and a end date also).
You need to add custom field to posts by adding a metabox to post screen, easyly with ACF plugin, or by yourself coding it in your theme's functions.php or in a self made plugin...
For example _my_evt_date, you will find it in postmeta table as meta_key with a meta_value like 2020-12-24 string.
The idea is to make a query in this table to store in an array each post having such meta key, you can create a json multiple array with post_id, date, html to display ...
In the archive page showing your news posts thumbnails, look at html code of each article in the loop, you'll probably have a css class including the post id, maybe like "post-entry-3217", "post-entry-3218"....
It was my case but using a premium template i decide to use javascript with jQuery to:
- call my database query with jQuery.get to load in a js array my php array with dates information
- parse article blocks matching css class post-entry-xxxx,
- extract the post id xxxx
- create a loop and parse the js array till matching the related post_id
- insert with jQuery.append some html with date information above the related thumbnail
js :
jQuery(document).ready(function()
{
// only in the archive page
if( jQuery('.slide-entry').length )
{
jQuery.get({
url:'mywebsite-uri/wp-content/themes/my-child-theme/my-script.php',
success: function(data)
{
// Load in an array results
ckc_yaevt = jQuery.parseJSON(data);
jQuery('.slide-entry').each(function()
{
// Extract xxxx from each slide-entry-xxxx
var post_id = jQuery(this).attr('class').match(/\d+/);
// Parse array with posts having dates
for (var i=0; i<ckc_yaevt.length; i++)
{
if ( ckc_yaevt[i][0] === post_id[0] && ckc_yaevt[i][1] !== '' )
{
// Add html in the loop
jQuery('.slide-image',this).append(ckc_yaevt[i][1]);
break;
}
}
})
}
})
}
})
Result :