简体   繁体   中英

Add today's date as URL query string to external site in Wordpress

I want to add in today's date as a query string parameter in a Wordpress site.

I've got a booking link URL which unfortunately won't accept a request without a valid date.

http://bookingsiteurl.com/search?Date=2017-08-08&Service=ABC&Currency=USD

Is there any way to setup a custom function that can make today's date as a URL parameter universally available on my site?

Maybe in the format of a hidden field populated with today's date, that I can then reference in URLs similar to how many of the common form plugins can add form fields into a query string.

Eg.

http://bookingsiteurl.com/search?Date= {TODAYS_DATE}&Service=ABC&Currency=USD

Is this possible with custom function?

You can achieve this functionality using rewrite api in wordpress.

Create URL by daily based using wp-cron. Create one function that create a permalink by add_rewrite_url. After successfully create custom endpoint Call flush_rewrite_rules(), Then only your custom endpoint will work.

Refer below links for more details,

Rewrite_API : https://code.tutsplus.com/articles/the-rewrite-api-the-basics--wp-25474

WP-CRON : https://www.smashingmagazine.com/2013/10/schedule-events-using-wordpress-cron/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM