1141 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
KarmaThemes says

Hi everybody!

Thanks for checking out this thread. I hope you can assist me on this one:

Can I somehow create a conditional inside the metabox definition file, like this:

  1. I got a metabox asking below each post editor if this post should be added to the portfolio or not
  2. I got several advanced metaboxes like “add a slider to the item” “add a company” etc.
  3. I only want to display the advanced metaboxes of 2. if the selection of the metabox in 1. is set to yes

this is the pastie for the selection

I reckon it’s something like this? if(get_post_meta(get_the_ID(), 'portfolio_add_item', true) == 'yes') :

I did add such a conditional for the “add a slider” selection and it works in the frontend files, but it does not seem to work inside the metabox field files.

If any of you got a clue about this, please write here or contact me through our profile page, I could really use some help on this one.

Thanks a bunch! Mel for KarmaThemes

367 posts plop
  • Elite Author
  • Sold between 50 000 and 100 000 dollars
  • Beta Tester
  • Has been a member for 5-6 years
  • Grew a moustache for the Envato Movember competition
  • Referred between 50 and 99 users
  • Interviewed on the Envato Notes blog
+3 more
kimonoThemes says

Not sure if I got your problem but do you have the var $prefix define in your metabox code? Maybe it’s because your are looking for “portfolio_add_item” but it’s named with a prefix like “themeprefix_portfolio_add_item”.

438 posts
  • Exclusive Author
  • Has been a member for 3-4 years
  • United States
christopherjon says

I’m not sure how to add a metabox conditionally based on options selected in another metaboxe but I have done something similar to what your asking about in one of my themes and I used jquery to switch between stuff.

My setup is a dropdown select and depending on which option is selected different additional options are shown. The only difference is it’s all in the same metabox.

To get you started: http://api.jquery.com/change/

The demo has most of the work done for you already.

2566 posts Put a Donk On It
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Exclusive Author
  • Attended a Community Meetup
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 200 and 499 users
+5 more
ThemeProvince says

You cannot hide wordpress meta boxes conditionally using php so you have to hack WordPress using jquery/js.