vegemite4me
vegemite4me

Reputation: 6856

WordPress - How to map a URL path to a WP_Query?

I am new to WordPress development and have created a custom type of event. I would now like to create a page which shows all upcoming events.

An event has the following fields:

This works, and I have used manage_edit-{$post_type}_columns to create an admin UI that allows for sorting by event_date. So far so good. :-)

But now I want to map a URL like www.example.com/upcoming-events to a page which shows:

I need some help joining up a few dots ... I guess that I will need to use WP_Query. But how do I map the URL path to a page with this WP_Query?

Upvotes: 0

Views: 322

Answers (1)

Kulikov Sergey
Kulikov Sergey

Reputation: 265

Just create page with slug upcoming-events and place your custom shortcode (for instance, shortcode [upcoming_events]) inside page's content.

Then add the shortcode definition inside your functions.php:

add_shortcode('upcoming_events',function() {
    /* Use WP_Query and output the content you'd like to be displayed */
});

Upvotes: 1

Related Questions