Ordering or shorting custom Query in wordpress for events display according events date

 So first go to front-page.php and find events section 

And add below line in custom query to display events as custom event date fields

 'meta_key' => 'event_date',
            'orderby' => 'meta_value_num',
            'order' => 'ASC'

meta key for custom field name and order by meta_value_num because date is number and meta for that because wordpress treat custom fields as meta value. Order Ascending order mean new first.

Now i want hide that event which date passed so follow below code

 $today = date('Ymd');


'meta_query' => array(
                array(
                  'key' => 'event_date',
                  'compare' => '>=',
                  'value' => $today,
                  'type' => 'numeric'
                )
            )

and save meta query used for search any value and compare. numeric is why because date i number and save.

Comments

Popular posts from this blog

Basics Of PHP

Creating App.js for Node Application

WordPress Full Guide For Developer