February 23, 2024

Blog Posts

'name',
'order' => 'ASC',
'hide_empty' => false,
));

$blog_category_ids = array();
$news_category_ids = array();
$blog_categories = array();
$news_categories = array();

foreach ($all_categories as $category) {
$category_description = trim(
wp_strip_all_tags((string) $category->description)
);

if (strcasecmp($category_description, 'Blog Posts') === 0) {
$blog_category_ids[] = (int) $category->term_id;

// Match the previous hide_empty behavior in the Blog dropdown.
if ((int) $category->count > 0) {
$blog_categories[] = $category;
}
} elseif (strcasecmp($category_description, 'News') === 0) {
$news_category_ids[] = (int) $category->term_id;

if ((int) $category->count > 0) {
$news_categories[] = $category;
}
}
}

$available_categories = $blog_mode === 'news'
? $news_categories
: $blog_categories;

$selected_category = false;

if ($selected_category_slug !== '') {
foreach ($available_categories as $category) {
if ($category->slug === $selected_category_slug) {
$selected_category = $category;
break;
}
}

// Do not retain a category that does not belong to the current page mode.
if (!$selected_category) {
$selected_category_slug = '';
}
}

$query_args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 16,
'paged' => $paged,
's' => $search_term,
'ignore_sticky_posts' => true,
);

if ($selected_category) {
// Filter either page to one validated category from that page's allow-list.
$allowed_category_ids = array((int) $selected_category->term_id);
} elseif ($blog_mode === 'news') {
// News page: posts assigned to any category described as "News".
$allowed_category_ids = $news_category_ids;
} else {
// Blog page: posts assigned to any category described as "Blog Posts".
$allowed_category_ids = $blog_category_ids;
}

$query_args['tax_query'] = array(
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => !empty($allowed_category_ids)
? array_values(array_unique($allowed_category_ids))
: array(0),
'operator' => 'IN',
),
);

$blog_query = new WP_Query($query_args);
?>

class="mb-4 mb-md-5"
role="search"
>

name="blog_search"
value=""
placeholder=""
type="search"
>

have_posts()) : ?>
have_posts()) : $blog_query->the_post(); ?>

max_num_pages > 1) : ?>
$search_term,
'blog_category' => $selected_category_slug,
));
?>

$pagination_base,
'format' => '',
'current' => $paged,
'total' => $blog_query->max_num_pages,
'type' => 'list',
'add_args' => $pagination_args,
'prev_text' => '« Previous',
'next_text' => 'Next »',
));
?>

Categories


Chat Icon Hi, I’m Allie! How can I help you today? Open Icon