Skip to content

Commit

Permalink
Reset global $post and WP_Query after getting recent.
Browse files Browse the repository at this point in the history
  • Loading branch information
EarthlingDavey committed Oct 25, 2024
1 parent c05690a commit 79031d0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion deploy/config/init/fpm-start.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

if wp core is-installed 2>/dev/null; then
if wp core is-installed 2>/dev/null; then
# WP is installed.
wp sync-user-roles sync
else
Expand Down
10 changes: 8 additions & 2 deletions public/app/themes/clarity/src/components/c-article/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
$query_args = new SearchQueryArgs((new Agency())->getCurrentAgency()['wp_tag_id'], 'post', 1, 5, true);

// Run the query.
$query = new WP_Query($query_args->get());
$recent_query = new WP_Query($query_args->get());

// Reset the post data.
wp_reset_postdata();

?>
<!-- c-article starts here -->
Expand All @@ -44,9 +47,12 @@
<aside class="l-secondary">
<?php
echo '<h2 class="o-title">Recent blog posts</h2>';
foreach ($query->posts as $key => $post) {
$main_post = $post;
foreach ($recent_query->posts as $key => $post) {
include locate_template('src/components/c-article-item/view-blog-feed.php');
}
$post = $main_post;
unset($main_post);
?>
</aside>

Expand Down
28 changes: 11 additions & 17 deletions public/app/themes/clarity/src/components/c-last-updated/view.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
<?php
$post_id = get_the_id();
$post_type = get_post_type($post_id);
$terms = get_the_terms($post_id, 'agency');
$post_id = get_the_id();
$post_type = get_post_type($post_id);
$terms = get_the_terms($post_id, 'agency');
$term_names = is_array($terms) ? array_map(fn($term) => $term->name, $terms) : null;
?>
<!-- c-last-updated starts here -->
<section class="c-last-updated">

<?php
// Remove last reviewed from blog posts as it is not a content item that needs to be reviewed
if (! is_singular('post')) :
?>
<?php
// Remove last reviewed from blog posts as it is not a content item that needs to be reviewed
if (! is_singular('post')) : ?>
<p><span class="c-share-post__meta__date">Last reviewed: <?= the_modified_date('j F Y') ?></span></p>
<?php endif; ?>
<?php endif; ?>

<p><span class="c-share-post__meta__date">Content tagged as:
<?php
if (is_array($terms)) {
foreach ($terms as $term) {
echo ' ' . $term->name . ', ';
}
}
?>
</span></p>
<p>
<span class="c-share-post__meta__date">Content tagged as: <?= join(', ', $term_names) ?></span>
</p>
</section>
<!-- c-last-updated ends here -->
10 changes: 8 additions & 2 deletions public/app/themes/clarity/src/components/c-news-article/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
$query_args = new SearchQueryArgs((new Agency())->getCurrentAgency()['wp_tag_id'], 'news', 1, 6, true);

// Run the query.
$query = new WP_Query($query_args->get());
$recent_query = new WP_Query($query_args->get());

// Reset the post data.
wp_reset_postdata();

?>

Expand All @@ -37,9 +40,12 @@

<?php
echo '<h1 class="o-title">Recent news</h1>';
foreach ($query->posts as $key => $post) {
$main_post = $post;
foreach ($recent_query->posts as $key => $post) {
include locate_template('src/components/c-article-item/view-news-feed.php');
}
$post = $main_post;
unset($main_post);
?>

</aside>
Expand Down

0 comments on commit 79031d0

Please sign in to comment.