• Resolved Richard Slade

    (@raslade)


    Hi Guido

    Me again. This time I’m trying to hook into the event categories to apply an add_action in my theme functions.php and have tried in_event_category but no luck. Any thoughts would be great.

    Richard

    • This topic was modified 7 years, 5 months ago by Richard Slade.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Guido

    (@guido07111975)

    Hi Richard,

    What are you trying to achieve?

    Guido

    Thread Starter Richard Slade

    (@raslade)

    Hi Guido

    I have a hook that adds a custom menu to posts from specific categories and would like to include event categories too.

    Thanks
    Richard

    Plugin Author Guido

    (@guido07111975)

    Hi,

    You cannot add the event cats to your custom menu via the menu page in dashboard?

    If this is not what you mean or want, you should add your hook here so I can take a look.

    Guido

    Thread Starter Richard Slade

    (@raslade)

    Hi Guido

    Here’s the code i’m using in the theme functions not via the menu.

    
    add_action('wp_footer', 'ava_after_main_title_mod');
    function ava_after_main_title_mod() {
    	if ( in_category('1') || in_category('2') || in_category('3') || in_category('4') || in_category('5') || in_category('6') || in_category('7') ){
    	echo "
    <div id='custom-fullwidth'>";
    	echo do_shortcode("[shortcode]");
    	echo "</div>
    ";
    }
    }
    

    Richard

    Plugin Author Guido

    (@guido07111975)

    Hi Richard,

    As far as I know you should use has_term() for that:

    
    if( has_term( 'your-event-category', 'event_cat' ) ) {
        // do something
    }
    

    event_cat is the taxonomy name that my plugin uses.

    More explanation about this here.

    Guido

    Thread Starter Richard Slade

    (@raslade)

    Hi Guido

    With a slight tweak that works within my existing hook.

    Spot on thank you.
    Richard

    Plugin Author Guido

    (@guido07111975)

    Hi,

    Great, because I haven’t tested it myself (yet).

    So I will mark this topic “resolved”.

    Guido

    Thread Starter Richard Slade

    (@raslade)

    Hiya

    Yes here’s the code in case needed.

    
    add_action('wp_footer', 'ava_after_main_title_mod');
    function ava_after_main_title_mod() {
    	if ( in_category('1') || in_category('2') || in_category('3') || in_category('4') || in_category('5') || in_category('6') || in_category('beauty')
    || has_term( 'category-1', 'event_cat' ) || has_term( 'category-2', 'event_cat' ) || has_term( 'category-3', 'event_cat' ) || has_term( 'category-4', 'event_cat' ) || has_term( 'category-5', 'event_cat' ) || has_term( 'category-6', 'event_cat' ) || has_term( 'category-7', 'event_cat' ) ){
    	echo "
    <div id='custom-fullwidth'>";
    	echo do_shortcode("[shortcode]
    	[/av_submenu]");
    	echo "</div>
    ";
    }
    }
    

    Richard

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Hook in to event category’ is closed to new replies.