Wanting to populate a HTML field with the latest post from a specific custom post type

By: Dayne Coulson-Hoffacker | Asked: 01/24/2023
ForumsCategory: Code HelpWanting to populate a HTML field with the latest post from a specific custom post type
Dayne Coulson-Hoffacker asked 2 years ago
Hi, I'm trying to see if it's possible to populate an HTML field in a form with the latest post for a specific custom post type. I have managed to get this far:
add_filter('frm_setup_new_fields_vars', 'frm_populate_posts', 20, 2);
add_filter('frm_setup_edit_fields_vars', 'frm_populate_posts', 20, 2); //use this function on edit too
function frm_populate_posts($values, $field){
  if($field->id == 8){ //replace 125 with the ID of the field to populate
    $posts = get_posts( array('post_type' => 'volumes', 'post_status' => array('publish', 'private'), 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC'));
    foreach($posts as $p){
      echo '
' . $p->post_title . '
';
    }
  }
  return $values;
}
The issue is that it's being appended to the .form-wrapper div instead of the HTML field div (Field ID=21). I've attached screenshots for your reference. Any help would be greatly appreciated. Thanks
Attachments
1 Answers
Victor Font answered 2 years ago

According to your screen print, $field->id == 8 is executing on the section header, not the HTML field, which should be $field->id == 21. Change your code as suggested, and let us know what changes. All Formidable fields can be used with the two hooks you are using. When nesting fields, always address the field directly in your code and the field wrapper.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right