0

I need to show the event date instead of the (default) post date for each post.

How can I do this?

I tried with Event Post plugin, but I can't get the event date and put it overwriting the published post date.

I tried with a custom field too (using Advanced Custom Field plugin), but I have the same problem: I can't replace the post date with the "date picker field".

For me it's important to use the default post format of wp and not a plugin that adds item "Events" in the wp backend menu.

How can I resolve this? IMO the wp developers should include the possibility to change the date status from published to event date.

Many thanks in advance.

1
  • If you want to use Advanced Custom Fields, this is how to display a date - put this in your single.php / index.php / archive.php template(s) in your theme where you want the date to display: advancedcustomfields.com/resources/date-picker/#template-usage That is how to change the display on the site. In the admin, you'll still have the post date as the day you published the post.
    – Michelle
    Nov 23 '16 at 17:22
1

Ok, great. It is using the posts for concerts, parties...etc.

You need to create a plugin:

Simply, create a folder inside the /wp-content/plugins and name is /my-events-plugin

Create a new PHP file, name it my_events_plugin.php, and use the following template:

https://www.smashingmagazine.com/2011/09/how-to-create-a-wordpress-plugin/

There is this tutorial that will get you to adding the custom field and save it:

https://www.smashingmagazine.com/2011/10/create-custom-post-meta-boxes-wordpress/

Hope this gets you going :)

5
  • Hello, thank you for your help. Yes, I mean events, such as concertes, parties, etc... But I need to use the default posts as events, because my theme get them in the homepage layout. ;) Now, I'm using the No Future Posts plugin, that allows to put a date in the future in a post and to show it. But this isn't the best solution, a better solution is by a custom field, but I don't know how can I change the post date with the event_date on the frontend.
    – ste_yeu
    Nov 23 '16 at 12:36
  • Great... I'm happy I understood.... Heheheheh...
    – TDEgypt
    Nov 23 '16 at 16:42
  • Ok, will edit my answer above shortly ;-)
    – TDEgypt
    Nov 23 '16 at 16:42
  • Answer edited :)
    – TDEgypt
    Nov 23 '16 at 17:09
  • Let me know how it went with you, and if I can be of any further help, just reply back :). Cheers
    – TDEgypt
    Nov 23 '16 at 22:16
2

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 :

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.