Home › Forums › General Issues › Combining wp_kses with get_field › Reply To: Combining wp_kses with get_field
// Strip all HTML tags from ACF fields
function bf_acf_kses( $value, $post_id, $field ) {
return do_shortcode( wp_strip_all_tags( $value ) );
}
// Apply to text fields in Teamleden backend
add_filter('acf/format_value/type=text', 'bf_acf_kses', 10, 3);
// Populate columns for Teamlid CPT admin page
function bf_populate_team_member_columns( $column, $post_id ) {
// Name
if ( 'name' === $column ) {
echo the_field( 'team_member_name' );
}
// Function
if ( 'function' === $column ) {
echo the_field( 'team_member_function' );
}
// Date added
if ( 'date_added' === $column ) {
echo get_the_date();
}
}
add_action( 'manage_bf_team_member_posts_custom_column', 'bf_populate_team_member_columns', 10, 2);
// Create Teamlid CPT shortcode
function bf_team_members_shortcode() {
ob_start();
// Get the internal links CPT
$team_members = get_posts(
array(
'numberposts' => -1,
'post_type' => 'bf_team_member',
'orderby' => 'menu_order',
'order' => 'ASC',
),
);
// Create an empty team member list
$team_list = array();
// Open unordered list element
echo '<ul class="bf-team-list">';
// Loop through the posts and build the team member list
foreach ( $team_members as $team_member ) {
$name = $team_member->team_member_name;
$function = $team_member->team_member_function;
$bio = $team_member->team_member_bio;
$photo_id = $team_member->team_member_photo;
$photo = wp_get_attachment_image( $photo_id, '360' );
$gif_id = $team_member->team_member_gif;
$gif = wp_get_attachment_image( $gif_id, '360' );
$team_list[] = '
<li class="et_pb_column bf-person-column bf-team-member">
<div class="et_pb_module et_pb_image bf-team-member-photo">
<span class="et_pb_image_wrap ">' . $photo . '</span>
</div>
<div class="et_pb_module et_pb_image bf-team-member-gif">
<span class="et_pb_image_wrap">' . $gif . '</span>
</div>
<div class="et_pb_module et_pb_text">
<div class="et_pb_text_inner">
<h3 class="bf-team-member-name">' . $name . '</h3>
<h4 class="bf-team-member-function">' . $function .'</h4>
<p class="bf-team-member-bio">' . $bio . '</p>
</div>
</div>
</li>
';
}
// Get string from array
$team_list_html .= implode('', $team_list);
// Output link list, but strip all non-allowed tags first
echo wp_kses_post( $team_list_html );
// Close unordered list element
echo '</ul>';
return ob_get_clean();
}
add_shortcode( 'team_members', 'bf_team_members_shortcode' );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re hard at work on ACF 6.1, and Beta 1 is now available 🚀
— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.