WordPress 6.0 upgrade caused my custom function to stop working
Not working on WordPress 6.0: https://thealliance.health/for-providers/resources/provider-news-archives/
Working dev site on WordPress 5.9.3: https://ccahdev.wpengine.com/for-providers/resources/provider-news-archives/
Here is the function if somebody can spot what may have been deprecated:
function wpb_postsbycategory2022() {
$posts = get_posts( array(
'category_name' = 'Provider News',
'nopaging' = true,
'orderby' = 'date',
'order' = 'DESC', // it's DESC; not DSC
// There's no use setting posts_per_page when nopaging is enabled.
// Because posts_per_page will be ignored when nopaging is enabled.
) );
$_year_year = ''; // previous years value
$_year_mon = ''; // previous year-month value
$_has_grp = false; // TRUE if a group was opened
$_has_grpy = false; // TRUE if a group was opened
foreach ( $posts as $post ) {
setup_postdata( $post );
$time = strtotime( $post-post_date );
$year = date( 'Y', $time );
$mon = date( 'F', $time );
$year_mon = $year-$mon;
$year_year = $year;
// Open a new group for year.
if ( $year_year !== $_year_year ) {
// Close previous group, if any.
if ( $_has_grpy ) {
echo '/div!-- .year --';
}
$_has_grpy = true;
echo div class='year' id='year$year';
echo h2$year/h2;
}
if ( $year_mon !== $_year_mon) {
// Close previous group, if any.
$_has_grp = true;
echo 'div class=month';
echo span$mon/span;
}
// Display post title.
if ( $title = get_the_title() ) {
echo diva href='/?p={$post-ID}'{$post-post_title}/a/div;
}
if ( $year_mon !== $_year_mon) {
// Close previous group, if any.
echo '/div!-- .month --';
}
$_year_mon = $year_mon;
$_year_year = $year_year;
}
// Close the last group, if any.
//
if ( $_has_grpy ) {
echo '/div';
}
/* Restore original Post Data */
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;
wp_reset_postdata();
}
// Add a shortcode
add_shortcode('categoryposts2022', 'wpb_postsbycategory2022');
Thank you for any assistance!
Topic deprecation functions Wordpress
Category Web