StonehengeCreations

Placeholder for WP Category in Events Manager

Aug 28th, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Adds a custom Events Manager placeholder to display the WordPress category.
  4.  *
  5.  * @param  string $replacement The string to be shown in the front end.
  6.  * @param  object $EM_Event    The current Events Manager Event object.
  7.  * @param  string $placeholder The current placeholder (#_PLACEHOLDER).
  8.  * @return string
  9.  */
  10. function stonehenge_em_placeholder_wp_category( $replacement, $EM_Event, $placeholder ) {
  11.     if( '#_WPCATEGORY' === $placeholder ) {
  12.         $categories = get_the_category( $EM_Event->post_id );
  13.         foreach( $categories as $category ) {
  14.             $replacement = $category->name;
  15.         }
  16.     }
  17.     return $replacement;
  18. }
  19. add_filter( 'em_event_output_placeholder', 'stonehenge_em_placeholder_wp_category', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment