1141 posts
  • 7 Years of Membership
  • Affiliate Level 1
  • Author Level 6
  • Collector Level 4
+3 more

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

422 posts plop
  • Trendsetter
  • 8 Years of Membership
  • Author Level 7
  • Weekly Top Seller
+10 more

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
  • 6 Years of Membership
  • Exclusive Author
  • United States

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.

2627 posts Put a Donk On It
  • Weekly Top Seller
  • Elite Author
  • Exclusive Author
  • Featured Author
+11 more

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