• Resolved chrishe

    (@chrishe)


    Hi, in the event list page I show a button that has a link to another site, which has the last part of address = %postname% i.e. the “slugified” version of EventName (NOT #_EVENTNAME) e.g. https://somesite/%postname%

    Is there currently anyway to do this?
    Could you add an Event placeholder for this please!

    Thanks
    Chris

Viewing 7 replies - 1 through 7 (of 7 total)
  • Could you look here, please?
    https://wp-events-plugin.com/documentation/placeholders/

    Simply use #_EVENTURL

    Thread Starter chrishe

    (@chrishe)

    Hi, thanks for your reply.
    But not quite what I want – I believe that #_EVENTURL give the WHOLE url, whereas I just want the %postname%
    E.G. for an event with title “My Event”
    #_EVENTURL = ‘https://mysite/events/my_event’,
    %postname% = ‘my_event’
    Then I can build a link to associated website “https://other_site/blah/my_event”
    Hope that is clear!
    Thanks

    You will have to do that with custom coding.

    And I can personally not think of any reason why you would want to create your own slug… If you want it to be usable/visitable, it should be stored by WP anyway…

    You could look into sanitize_title() in the WP Codex.
    Btw, a slug and URL should not have underscores. If presented as a link visitors won’t see it’s one thing, because the automated link underlining. That’s why all slugs in WP are always with dashes.

    Thread Starter chrishe

    (@chrishe)

    Thanks for your reply – the underscores were only for the post above, agreed dashes for urls.
    I think I described why I want to do this above! I want to “automatically” show a link to another site against each event in the event list.
    I know the other site “root part” of the url to go to. I also know that the final part will match the %postname% (i.e. last part of the url)

    Combining these two parts will enable the links to be formed without the author having to remember to set a custom attribute for each event. I hope that now makes sense!
    Thanks

    I do understand what you would like, but what I do not understand is why you want to direct your visitors away from your site… Google Analytics measures how long someone stays on your site for your and uses that for Google Search Ranking, calculating bounce rates, etc. So why shorten that?? But okay…..

    You still need custom coding, like I said. That is not something that is built-in.
    As I said already: look into sanitize_title(). WordPress uses that to go from post_title to post_name, so you can use that too.
    You will need to create your own custom placeholder anyway.

    Here’s the official EM Tutorial on how to create your own custom placeholders:
    https://wp-events-plugin.com/tutorials/create-a-custom-placeholder-for-event-formatting/ ??

    Here you go.

    function redirect_away_placeholder( $replacement, $EM_Event, $result ) {
    	switch($result) {
    		'#_EVENTSLUGURL':
    			$event_slug = santize_title( $EM_Event->output( "#_EVENTNAME" ) );
    			$url_out = 'https://pleasegotoanotherwebsite/';
    			$replacement = $url_out . $event_slug;
    		break;
    	}
    	return $replacement;
    }
    add_filter('em_event_output_placeholder', 'redirect_away_placeholder', 10, 3);
    Thread Starter chrishe

    (@chrishe)

    Thanks Patrick!
    OK, I can understand you are puzzled! Our site enables sailors to attend racing events. Two people are required to sail in each boat.
    So some sailors may be keen to enter the race, but they need a crew for their boat, Other sailors may be looking for a boat to sail in. The “other Site” I mentioned is a crew/helm finder.
    So basically it is part of a service we offer to our members, to help match up helms and crews so they can enter our racing events! The is more important than keeping them strapped into our site for Google analytics!
    Thanks for your code, that is very helpful.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to use %postname% as event attribute’ is closed to new replies.