Add Custom Fields to Post Type


I added a Custom Post Type as radio button to my form.
Now I want to display also the Custom Field Values from the Posts at the frontend.

At the moment only the Post names would show up in the form. But I want to show also the following custom fields and one Taxonomy:

  • image
  • price
  • warranty
  • usp 1
  • usp 2
  • usp 3
  • brand

How do I those ACF values and Taxonomy at each Post in the form based on Post ID ?

I think you’re asking about getting post values based on a post ID which isn’t really related to GF?

You’re looking for something like this:

Or googling ‘wordpress get post taxonomy by post id’

I think that will provide better results than this forum.

add_filter( 'gform_field_choice_markup_pre_render_1_56', 'my_fields', 10, 4 );
function my_fields( $choice_markup, $choice, $field, $value ) {
    $posts = get_posts( 'numberposts=-1&post_type=my_cpt&order=ASC' );

    foreach ( $posts as $post ) {
        $img = get_field('image', $post->ID);
        $brandImage = get_field('brand_image', $post->ID);

        if ($field->get_input_type() == 'radio' && rgar( $choice, 'value' ) == $post->ID  ) {
            $warranty     = '<span class="warranty">'. $post->warranty .'</span>';
            $image          = '<img src="'. esc_url($image['url']) .'" class="image" />';
            $brand         = '<img src="'. esc_url($brandImage['url']) .'" class="brand-image" />';
            $price          = '<div>'. $post->price_value .'</div>';
            $usps           = '<ul class="usps"><li>'. $post->usp1 .'</li><li>'. $post->usp2 .'</li><li>'. $post->usp3 .'</li></ul>';
            return str_replace( "</label>", "$warranty $image $brand $price $usps</label>", $choice_markup );

    return $choice_markup;

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.