I am using option tree in theme mode and child theme mode and I am trying to add new option types. The new option types will be based off of the post-select option type, but will only list posts from a specific category.
I created a new file and added it to the array of files to be included that begins on line 178 of ot-loader.php. In the new file I cut and pasted the post-select option type that begins on line 905 of /includes/ot-functions-options-type.php. You can see this new file here.
In my post select option type I appended a unique slug to the function name. I also put that slug on the css class .type-post-select for the format outer setting wrapper. In the post query post array I added a category parameter.
Then I added my new post-select option type to my theme options, hoping it would show only posts in the category I had set. It showed the posts from all categories. Interestingly enough the option was wrapped in .type-post-select. I also created a regular post-select, which did not have the modified css.
As an experiment I tired adding the category parameter to the original post-select option in the same way and it worked exactly as I expected–only showing posts from that category. Unfortunately I need to create 6 new post-selects each showing posts from a different category.
Clearly I am missing a step, but for the life of me I can not find it. I looked for some other place that option types need to be registered or something, but couldn’t find it…
What you’re trying to do can be accomplished without ever editing the core files in OptionTree. Add your custom option type functions to your themes
functions.php
and the following code, as well.This will auto load your functions into OptionTree and you don’t need to edit any of the core files. When you add new options, there are two requirements. One, all functions must be prepended with
ot_type_
. Two, when adding to the array of options your new array keys need to match the function name minusot_type_
, you can use either-
or_
when creating the key. So if you have a custom function namedot_type_super_awesome
you could add it to the filtered array with either:or
I hope that clears up any confusion. On a side note there are two
ot_type_post_select_a_5
in the file you created and I’m assuming the last one should beot_type_post_select_a_6
. Cheers!