Home › Forums › Plugin Support › Filter Hook to modify field content (options in a select menu)
- This topic has 12 replies, 4 voices, and was last updated 11 years, 8 months ago by Support.
-
AuthorPosts
-
November 22, 2012 at 8:15 am #2488December 27, 2012 at 8:10 pm #2720umbercodeMember
I know it has been a month since your question, but I am facing the same kind of problem. I need to fill a select-box with taxonomy terms. Like you I searched the code but found no filter or action hooks (in fact I would go sofar as to say I find the code a bit “unfriendly” to make an understatement).
Anyway, I found a solution to my problem after I found that the fields are stored in the database options table (wp_options) under the name “user_meta_fields”. So what I did was read that field in my code and fill the appropriate array-key with my taxonomy, then store it back again in the database. The only downside to this is that this code needs to run everytime you load a page, but it’s better than nothing.
If you find (or found) a better solution I am all ears. Hope this helps.December 27, 2012 at 10:57 pm #2721toddz70Member@umbercode — Nope, I did not come up with anything on my own, and never heard back from the developer about it. Thanks for the idea.. maybe i’ll give it a shot.
February 23, 2013 at 1:19 am #3139groupewibiMemberSame request there ! I would like to have a field displaying a list of custom type, and taxonomy. My problem is a bit more complex as it as to use hierarchical taxonomy also.
February 23, 2013 at 3:00 am #3147SupportMemberHello,
With version 1.1.3rc2 you can use filter hook “user_meta_field_config”, here is a quick example:
add_filter( 'user_meta_field_config', 'user_meta_field_config_function', 10, 3 );
function user_meta_field_config_function( $field, $fieldID, $formName ){
if( $fieldID != 'Field Id that you want to control' )
return $field;$field['options'] = "value1, value2, value3";
// "val1=value1, val2=value2, val3=value3"; for key valuereturn $field;
}
For using taxonomy or case of array you can use “implode” function. BTW, with next release direct array can be assigned as option.
Thanks.
- This reply was modified 11 years, 9 months ago by Support. Reason: replace not equal to sign
February 24, 2013 at 1:36 pm #3163groupewibiMemberWhen will be the next release ?
February 24, 2013 at 1:51 pm #3164groupewibiMemberHonnesty, i can pay for it first, and second, that would be a killer feature for this plugin.
March 5, 2013 at 3:49 pm #3231groupewibiMemberOk for that. I did that based on the exemple :
add_filter( ‘user_meta_field_config’, ‘user_meta_field_config_function’, 10, 3 );
function user_meta_field_config_function( $field, $fieldID, $formName ){
if( $fieldID != ’27’ ) return $field;
$secteurs = get_categories(‘taxonomy=localisation’.’&hide_empty=0′.’&pad_counts=1′.’&name=club_secteur’.’&child_of=0′);
foreach($secteurs as $secteur) :
$categories[] = $secteur->name.’=’.$category->term_id;
endforeach;$field[‘options’] = implode(‘,’, $categories);
// “val1=value1, val2=value2, val3=value3”; for key value
return $field;}
It showing the term name, but the it’s not showing the id of the term (value).
Any help there ?
March 5, 2013 at 5:01 pm #3232groupewibiMemberOk, found the solution.
add_filter( ‘user_meta_field_config’, ‘user_meta_field_config_function’, 10, 3 );
function user_meta_field_config_function( $field, $fieldID, $formName ){
if( $fieldID != ’27’ ) return $field;
$secteurs = get_categories(‘taxonomy=localisation’.’&hide_empty=0′.’&pad_counts=1′.’&name=club_secteur’.’&child_of=0′);
foreach($secteurs as $secteur) :
$output .= $secteur->term_id.’=’.$secteur->name.’,’;
endforeach;$field[‘options’] = $output;
// “val1=value1, val2=value2, val3=value3”; for key value
return $field;}
March 6, 2013 at 4:58 pm #3253groupewibiMemberProblem. How we can remove the last empty value ( , ) ?
March 7, 2013 at 5:44 pm #3313groupewibiMemberIs there is any option in $field[‘options’] to put a empty (-1) option selected by default ?
March 7, 2013 at 5:44 pm #3314groupewibiMemberIs there is any option in $field[\’options\’] to put a empty (-1) option selected by default ?
March 8, 2013 at 4:42 pm #3324SupportMemberYou can add following codes after the end of foreach cluse.
$output = ',' . trim( $output, ',' );
Thanks.
-
AuthorPosts
- You must be logged in to reply to this topic.