Using Gravity Forms ‘gform_embed_post_types’ PHP action

The gform_embed_post_types Gravity Forms PHP filter allows users to modify the post types presented in the Embed Form flyout.

Usage

To use this filter for all forms:

add_filter('gform_embed_post_types', 'your_function_name');

Parameters

  • $types (array): An associative array of post types.

More information

See Gravity Forms Docs: gform_embed_post_types This filter was added in Gravity Forms v2.6.

Examples

Add the post type ‘book’

This example adds the post type with slug book to the Embed Form flyout.

add_filter('gform_embed_post_types', function($types) {
    $types[] = array('slug' => 'book', 'label' => 'Book');
    return $types;
});

Remove the post type ‘post’

This example removes the standard post post type from the Embed Form flyout.

add_filter('gform_embed_post_types', function($types) {
    $types = array_filter($types, function($type) {
        return $type['slug'] != 'post';
    });
    return $types;
});

Add multiple custom post types

This example adds two custom post types, product and testimonial, to the Embed Form flyout.

add_filter('gform_embed_post_types', function($types) {
    $types[] = array('slug' => 'product', 'label' => 'Product');
    $types[] = array('slug' => 'testimonial', 'label' => 'Testimonial');
    return $types;
});

Remove all post types except ‘page’

This example removes all post types from the Embed Form flyout except the page post type.

add_filter('gform_embed_post_types', function($types) {
    $types = array_filter($types, function($type) {
        return $type['slug'] == 'page';
    });
    return $types;
});

Add a custom label for a post type

This example adds a custom label for the post post type in the Embed Form flyout.

add_filter('gform_embed_post_types', function($types) {
    foreach ($types as &$type) {
        if ($type['slug'] == 'post') {
            $type['label'] = 'Blog Post';
        }
    }
    return $types;
});