256 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Won a competition
+5 more
der says

Ivor, you can use the in_category($cat) template tag, to determine if the post is on the specific category. $cat can be either the category slug, the category name, or the category ID.

So, you can use the template tag to determine if the post being edited (since the post being created doesn’t have a category yet), has the specific category. This way you can conditionally include the post metabox, based on the category of your preference.

For example:

if ( in_category('Design')  ) {
    add_meta_box( ... args ... );
}
448 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
webinpixels says

Sorry about my english,

How about adding checkbox or select option and place a jQuery “onchange” function to detect the value, when value = 1, then the metabox will visible..yeah old trick just simple make the metabox container hidden. :) but we must make the checkbox/select option as data too, so when people edit their post the metabox will keep hidden if the checkbox/select option value = 0. And simple add the logical function on the metabox container



<select name="_useornot">
<option selected value="0">No</option>
<option value="1">Yes</option>
</select>

<div class="metabox_cont" <?php if(get_post_meta($postID, '_useornot', true) == 0) echo'style="display:none;"; ?>>

---metabox code



hehe, never try this..but maybe can help you :D

4336 posts ThemeForest Reviewer
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Member of the Envato Team
+12 more
Ivor Envato team says
Ivor, you can use the in_category($cat) template tag, to determine if the post is on the specific category. $cat can be either the category slug, the category name, or the category ID.

So, you can use the template tag to determine if the post being edited (since the post being created doesn’t have a category yet), has the specific category. This way you can conditionally include the post metabox, based on the category of your preference.

For example:

if ( in_category('Design')  ) {
    add_meta_box( ... args ... );
}

Thanks a lot Der, I’ll definitely try it.

@Themesguy Thanks, I’ll give it a try :) let’s see.

72 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 100+ members
  • Has sold $125,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+6 more
Themolution says

Great one, i was searching for that, thanks mate.

by
by
by
by
by
by