1

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.

1
  • what the name of the plugin you are using to create the business directory categories?
    – Bainternet
    Commented Aug 3, 2011 at 12:20

2 Answers 2

2

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!

1
  • not sure if that's what she meant and your code wont check for custom taxonomy but for a post type.
    – Bainternet
    Commented Aug 3, 2011 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.