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:
- I got a metabox asking below each post editor if this post should be added to the portfolio or not
- I got several advanced metaboxes like “add a slider to the item” “add a company” etc.
- I only want to display the advanced metaboxes of 2. if the selection of the metabox in 1. is set to yes
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
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”.
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.
You cannot hide wordpress meta boxes conditionally using php so you have to hack WordPress using jquery/js.