Advertisement
eventsmanager

custom category has_parent conditional

May 6th, 2022
20
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // sample usage: {has_category_parent} content {/has_category_parent}
  3. add_action('em_event_output_condition', 'my_em_custom_category_has_parent', 100, 4);
  4. function my_em_custom_category_has_parent($replacement, $condition, $match, $EM_Event){
  5. if ( preg_match('/^has_category_parent$/',$condition, $matches) ){
  6. $count_cats = count($EM_Event->get_categories()->categories) > 0;
  7. if( $count_cats <= 1 ){
  8. foreach($EM_Event->get_categories() as $EM_Category){
  9. if( $EM_Category->parent > 0){
  10. $replacement = preg_replace("/\{\/?$condition\}/", '', $match);
  11. }else{
  12. $replacement = '';
  13. }
  14. }
  15. }else{
  16. $replacement = '';
  17. }
  18. }
  19. return $replacement;
  20. }
Advertisement
RAW Paste Data Copied
Advertisement