Thank you very much @hube2!
Thank you @hube2. I noticed this indeed makes my forms work. Also, if I have a wysiwyg field and I get it like the_sub_field it will work without errors but only if I don’t have any formatting. As soon as I actively align the text left, right or justify i get errors like below. If I call the field with echo get_sub_field these errors don’t show up:
Detected Potentially Unsafe HTML Modification
#0 /home/client1/web/client1website.nl/public_html/wp-includes/class-wp-hook.php(324): print_backtrace_for_unsafe_html_removal('...', '...', Array, false)
#1 /home/client1/web/client1website.nl/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#2 /home/client1/web/client1website.nl/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#3 /home/client1/web/client1website.nl/public_html/wp-content/plugins/advanced-custom-fields-pro/includes/api/api-template.php(942): do_action('...', '...', '...', Array, false)
#4 /home/client1/web/client1website.nl/public_html/wp-content/themes/client1/page.php(108): the_sub_field('...')
#5 /home/client1/web/client1website.nl/public_html/wp-includes/template-loader.php(106): include('...')
#6 /home/client1/web/client1website.nl/public_html/wp-blog-header.php(19): require_once('...')
#7 /home/client1/web/client1website.nl/public_html/index.php(17): require('...')
Can I expect any impact on performance when calling all fields with echo get_field / echo get_sub_field?
I have a similar situation. Would I correct this:
<?php if( have_rows('page_content') ): ?>
<?php while( have_rows('page_content') ): the_row(); ?>
<?php if( get_row_layout() == 'page_content' ): ?>
<div class="training">
<?php the_sub_field('page_description_100'); ?>
</div>
<br>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
By using this?
<?php if( have_rows('page_content') ): ?>
<?php while( have_rows('page_content') ): the_row(); ?>
<?php if( get_row_layout() == 'page_content' ): ?>
<div class="training">
<?php echo esc_html( the_sub_field('page_description_100') ); ?>
</div>
<br>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
The notice is still visible in the dashboard. (I’m using the classic editor with some CF7 and YouTube in the WYSIWYG field.)
Thanks in advance!
Thank you very much @hube2. I was able to solve it by getting rid of strtotime() all together.. For reference here my code:
<?php
// Retrieve the list of posts from your CPT 'accreditations' with ACF fields 'description' and 'date'
$posts = get_posts(array(
'post_type' => 'accreditaties',
'posts_per_page' => -1,
));
// Create an associative array to group posts by year
$groupedPosts = array();
// Iterate through the list of posts and assign each post to the corresponding year
foreach ($posts as $post) {
$date = get_field('acc_aanvangsdatum', $post->ID);
$parsedDate = DateTime::createFromFormat('d/m/Y', $date);
$year = $parsedDate->format('Y');
if (!isset($groupedPosts[$year])) {
$groupedPosts[$year] = array();
}
$groupedPosts[$year][] = $post;
}
// Sort the grouped posts by year in descending order
krsort($groupedPosts);
// Iterate through the grouped posts and generate the HTML markup for each year's section
foreach ($groupedPosts as $year => $posts) {
echo '<button class="accordion"><h4>' . $year . '</h4></button>';
echo '<div class="panel accreditaties">';
?>
<div class="grid-container">
<div class="grid-item" id="grid-item-title"><p>Aanvangsdatum</p></div>
<div class="grid-item" id="grid-item-title"><p>Titel</p></div>
<div class="grid-item" id="grid-item-title"><p>Status</p></div>
<div class="grid-item" id="grid-item-title"><p align="right">Uren</p></div>
<?php
// Sort the posts within each year section by date in descending order
usort($posts, function($a, $b) {
$dateA = DateTime::createFromFormat('d/m/Y', get_field('acc_aanvangsdatum', $a->ID));
$dateB = DateTime::createFromFormat('d/m/Y', get_field('acc_aanvangsdatum', $b->ID));
return $dateB <=> $dateA;
});
foreach ($posts as $post) {
$title = get_the_title($post->ID);
$acc_aanvangsdatum = get_field('acc_aanvangsdatum', $post->ID);
$acc_status = get_field('acc_status', $post->ID);
$acc_uren = get_field('acc_uren', $post->ID);
$acc_beschrijving = get_field('acc_beschrijving', $post->ID);
?>
<div class="grid-item"><p><?php echo $acc_aanvangsdatum ?></p></div>
<div class="grid-item"><p><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $title ?></a></p></div>
<div class="grid-item status"><p><?php echo $acc_status ?></p></div>
<div class="grid-item uren"><p align="right"><?php echo $acc_uren ?></p></div>
<?php
}
echo '</div>'; // Close the grid-container
echo '</div>'; // Close the panel for the current year
}
?>
<script>
var years = document.getElementsByClassName("year");
var i;
for (i = 0; i < years.length; i++) {
years[i].addEventListener("click", function() {
var posts = this.nextElementSibling;
if (posts.style.display === "block") {
posts.style.display = "none";
} else {
posts.style.display = "block";
}
});
}
</script>
<style>
.grid-container {
display: grid;
grid-template-columns: 17% auto 16% 5%;
grid-column-gap: 0.5em;
}
.grid-item {
border: 0px solid black;
padding: 0em;
}
.grid-items-status-uren {
display: contents;
}
</style>
Okey thank you! I’ll ask him.
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 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.