Support

Account

Home Forums Add-ons Flexible Content Field Using get_post_meta to get Flexible Fields?

Helping

Using get_post_meta to get Flexible Fields?

  • I’ll try and keep this as short, sweet, and concise as I can. So I’m letting users create JSON files for an API by filling out a Flexible Field. I need to build and save these JSON files anytime they updated the post so I don’t reach the limit of the number of times we can hit the API.

    Anyway, I need to use get_post_meta to pass the fields so I can build the JSON file. So here is what I have and these 3 work.

    $bc_id = get_post_meta( $post_id, 'page_biblio_2', true );
    $bc_uri = get_post_meta( $bc_id[0], 'request_uri', true );
    $bc_type = get_post_meta( $bc_id[0], 'type_of_request', true );

    But the next 4 are wrapped in a Flexible Field and do not work. What am I doing wrong?

    $bc_media = get_post_meta( $bc_id[0], 'media_type', true );
    $bc_audience = get_post_meta( $bc_id[0], 'audience', true );
    $bc_content = get_post_meta( $bc_id[0], 'content_class', true );
    $bc_custom = get_post_meta( $bc_id[0], 'custom_query', true );
  • This is an old question and you may have figured this out or moved on but the information may be helpful for others.

    To loop through a flexible content field to a repeater fields rows.

    
    $repeater = 'repeater_name';
    $count = intval(get_post_meta($post_id, $repeater, true));
    for ($i=0; $i<$count; $i++) {
      $subfield_value = get_post_meta($post_id, $repeater.'_'.$i.'_'.'subfield_name', true);
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Using get_post_meta to get Flexible Fields?’ is closed to new replies.