Posted: May 19, 2015 at 5:59 am
|
Hey guys – Curious if there’s an easy answer for this or if it’s been asked before and I’m just not finding it on the forums. If not, I’d be happy to open a priority support ticket. My site will host multiple events with the same Title (“Title of Class”). I have a custom field set up on each Event and I would like to append the value of this field to the URL of my event on Publish/Update – allowing these events to share titles and pretty slugs while maintaining a unique URL. What do you think is the best way of doing this? Thanks, |
Hi Phil, WordPress has a function that allows you to add custom arguments to a query. Its name is add_query_arg(). Here are a few references that show how to use add_query_arg: https://developer.wordpress.org/reference/functions/add_query_arg/ Here’s an example that shows how you can use add_query_arg to add a custom field (‘query_arg’) to the event post’s permalink:
|
|
One more idea, please see this stackexchange thread for an alternative solution: |
|
|
Thanks for the detailed response. I think I follow what is going on here… The function works as suggested, BUT… The slug of my similar event still appends the default serialization. (screenshot) I would like to have multiple events with the same title, yet unique URLs, without requiring an admin to edit the slug. Does that make sense? My preference would be to append the custom field to the default slug without the variable syntax. (ie /events/my-event-title/custom-field) I would be open to customizing the automatic slug behavior (ie automatically generate a slug of “/events/my-event-title-custom/” for the event My Title) if that is a better option. |
|
I forgot to link the screenshot. |
Phil, You’re looking at overriding core WordPress functionality, which isn’t something Event Espresso itself overrides. So the solution you’re looking for could also apply to regular WP posts and pages. I can recommend reviewing the code in the wp_unique_post_slug() function to see how the -2 gets added in the first place before you take a crack at removing it. Here’s a link to that function in WP Core trac: https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-includes/post.php#L3705 The solution I linked to above might work around that functionality. You could look into that idea. Or you can also use the wp_unique_post_slug filter on the function of the same name. You can see in WP core where it lets you filter what gets returned for the post slug. So instead of using add_query_args() to add a parameter, you could use that filter to append your custom unique slug key. |
|
The support post ‘Append Data (i.e Custom Field) to Event URL’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.