to create own conditional tags for business directory in wp

i want to create conditional tags for the business directory categories as the conditional tags which are provided are for normal categories.which do not work for the business directory categories.can i do ths? if yes, then how?

thanks in advance.

Related posts

Leave a Reply

2 comments

  1. you can use has_term to check if a post as a term which that is what “business directory categories” are (custom taxonomy terms).
    something like:

    if (has_term( $term, $taxonomy, $post_id )){
    //do your thing
    }
    

    if you want to check if you are in a specific term ( like is_category) you can use is_tax

    if (is_tax( $taxonomy, $term )){
    //do stuff
    }
    

    if you want to check if your object (post) is in a specific term ( like in_category) you can use is_object_in_term()

    if (is_object_in_term( $object_id, $taxonomy, $terms) ){
    //do stuff
    }
    
  2. I’m not sure what your “business directory” categories are. Are you using a specific plugin to create this business directory?

    Taking a stab in the dark, you’ve got two options. If these categories are the same categories under the “Posts” taxonomy, then you could use this:

    is_category('my-business-category');
    

    If, however, your using a special plugin that adds its own custom taxonomy (meaning you aren’t using the “posts” but you have a “directory” section in WP-admin, and you want to check if that is what the user is looking at, you would have to use something like this:

    Put this in your functions.php:

    function is_post_type($type){
        global $wp_query;
        if($type == get_post_type($wp_query->post->ID)) return true;
        return false;
    }
    

    and the you can use this to find the custom post type:

    is_post_type('business_post_type')
    

    Which I originally found here:

    If is custom post type

    Hope this helps!