PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Populate dropdown/list from post content

  1. Hello,

    I have a complex operation to put together and my knowledge of hooks, filters, and general php is minimal to say the least. I would appreciate some help here:

    I have a page with a list of downloads that are placed dynamically using a plug-in called MediaTags. Basically, all this does is allow me to categorize media and display it on a page according to category. Now, I need to be able to do several things on this page:

    1. Downloads are publicly available as long as users fill out a form first. So I thought I could link each file to another page with the form on it. This should only happen for non-members. Members who are logged in should be able to download directly from the downloads page, without being redirected, and without filling out anything. Any ideas how I can do this?

    2. Once a user lands on the form page, they should be given an option to download the file they clicked on, and any of the other files listed on the Downloads page - the posts regarding dynamically populating a field have pretty much gone over my head, so I am not sure how to get the list from the previous page into a dropdown/checkboxes/list on the form. Remember that the list of files is periodically updated, and is already called dynamically on the previous page, so this information cannot be hard-coded.

    3. Once the user has made his selection and filled out the form, the links for the download should appear on a redirected page, or can be sent to him via email (obviously, this will be based on the selections made by the user - as I understand it, the file urls would be the values of each item in the dropdown. How do I do that???).

    Where do I start with this kind of process? I checked the documentation for populating fields dynamically, but it might as well have been in cyrillic. I understood very little. Can anyone help?

    Posted 9 years ago on Monday August 13, 2012 | Permalink
  2. Okay, I've figured out how to do the first two items on my list, but I still need some help with populating a multiselect or checkbox field with the list of downloads. I have this code, which does nothing:

    add_filter('gform_field_value_dlfield', 'populate_dlfield');
    function populate_dlfield($value) {
        $dllist = get_attachments_by_media_tags('media_tags=download&display_callback_item=mediatags3');
        return $dllist;

    The 'display_callback_item' is a custom media_tags function, which displays the title and a link to the file as a value. What am I doing wrong here?

    function mediatags3($post_item, $size='')
    	$file_src 	= wp_get_attachment_url($post_item->ID, $size);
    	return '<option value='.$file_src.'>'.$post_item->post_title.'</option>';

    Can anyone help???

    Posted 9 years ago on Thursday August 30, 2012 | Permalink
  3. You said "display_callback_item" is a custom media_tags function. Yet, I don't see it in use here. Can you explain how that fits into the picture?

    Also you have a function mediatags3 here: where is that being used?

    I'm afraid we can't see the whole picture here.

    Posted 9 years ago on Friday August 31, 2012 | Permalink
  4. Let me see if I can explain:

    The data I am trying to extract is a list of downloads from a Wordpress media library. I have used a plugin called 'Media Tags' to assign tags/categories to attachments (PDF files), and created a custom function (mediatags3) to allow me to display PDF files as links (without this, the media-tags plugin returns a broken image icon, as it is primarily for images, not documents). In this case, I have set it to display as options in a select field.

    The 'display_callback' function is hidden in my comment above, but if you view it as plain text, you'll see the full code:
    $dllist = get_attachments_by_media_tags ('media_tags=download&display_callback_item=mediatags3');

    Essentially, I am displaying attachments as links, from a list of items tagged 'download'.

    I think I need to consolidate the two functions in order for the field to populate, but my php knowledge is primitive, to say the least. Do you think the media-tags code is incompatible with gravity forms?

    Posted 9 years ago on Friday August 31, 2012 | Permalink
  5. I can't see that code in your comment above. Can you please post the code to or and update this topic with the link to the code? That way we can see the full picture. Thank you.

    Posted 9 years ago on Friday August 31, 2012 | Permalink