• I need to know category ID in a plugin file. But when I type in the top of the file get_query_var(‘cat’);, the site stops working

Viewing 2 replies - 1 through 2 (of 2 total)
  • You did not provide enough information. Please put a comment in the code where you want to insert the get_query_var(), put the code in a pastebin, and post a link to it here.

    Also, tell us how ‘the site stops working’. Do you get an error message? Or the screen is blank?

    Thread Starter artnik7

    (@artnik7)

    vtxyzzy
    I’m already solve the problem but it was to complexly. In general I need to disable whole plugin for specific category (with slug “blog”). But any of default WP functions doesn’t works in the begin of plugin file, maybe thats because them should be used using add_filter or add_actions.

    I wrote a function

    function is_blog() {
    	$current_post_categs = get_the_category();
    	$is_blog = false;
    	foreach ($current_post_categs as $categ) {
    		if ($categ->category_nicename == 'blog' || $categ->slug == 'blog') {
    			$is_blog = true;
    		}
    	}
    	return $is_blog;
    }

    And now I’m use this function in the begin of any plugin function. For example:

    my_function() {
    	if (is_blog()) return;
    	// function content
    }
    add_filter('get_comment_link', 'my_function');

    It works, but there are many functions in this plugin and for each of them I’ve add “if (is_blog()) return;”.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to know category ID in plugin file?’ is closed to new replies.