WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use gravity forms and wp-favorites plugin (helps users select their favorite posts).

I am trying to auto-populate gravity form with the following snippet. It works pretty well but it shows only the first item in the list.

How can I get all items in the array?

add_filter("gform_field_value_circle", "populate_square");
function populate_square ($value) {
    $favs = wpfp_get_users_favorites();
    foreach ($favs as $fav){
        $list = get_the_title($fav);
    return $list;

This snippet shows me the title of the first selected post only. I would like to get a list of all the selected posts, how do I acheive that ?

FYI, I am trying to make use of the HOOK provided by gravity forms. You can see the code here.

Pleae let me know if I need to be more clear.

share|improve this question

closed as off-topic by mrwweb, Pieter Goosen, birgire, Johannes Pille, gmazzap Sep 2 '14 at 8:05

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – mrwweb, Pieter Goosen, birgire, Johannes Pille, gmazzap
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 1 down vote accepted

If it is a dropdown and you want to populate it with options may be use this filter

add_filter("gform_predefined_choices", "add_predefined_choice");
function add_predefined_choice($choices){
   $choices["My New Choice"] = array("Choice 1", "Choice 2", "Choice 3");
   return $choices;


gform_field_value_selection filter is for default value.

Give a look here http://www.gravityhelp.com/documentation/page/Developer_Docs

See if this works..

  add_filter("gform_field_value_selection", "populate_selection");
    function populate_selection ($value) {
        $favs = wpfp_get_users_favorites();
        $list = array();
        foreach ($favs as $fav){
        $list[] = get_the_title($fav);
        return $list;

share|improve this answer
It returns a text 'Array'. Any thoughts ? Thank you. – gurung Jan 3 '13 at 6:11
@gurung have edited my answer.. – Rajeev Vyas Jan 3 '13 at 6:21
No I did not edit your answer. and No it is not a drop down. But as indicated I have done a minor corrections in the parameter name and the function name, just to make sure they are not default values. I have also given a link to gravity forms to see the hook in action. Thank you for trying. – gurung Jan 3 '13 at 6:43
oops.. i thought you meant i edited your answer. Cn you help me further please. thnks – gurung Jan 3 '13 at 10:11
@gurung What kind of field it is? for ex. List field or some thing else? – Rajeev Vyas Jan 3 '13 at 11:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.