Skip to content

Commit

Permalink
fix: add api posts to cache to enable get_post (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbrink authored Nov 14, 2023
1 parent 875c7da commit 6b72de2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function addHooks(): void
add_filter('Municipio/Breadcrumbs/Items', [$this, 'modifyBreadcrumbsItems'], 10, 3);
add_action('pre_get_posts', [$this, 'preventSuppressFiltersOnWpQuery'], 200, 1);
add_action('pre_get_posts', [$this, 'preventCacheOnPreGetPosts'], 200, 1);
add_action('Municipio/Content/ResourceFromApi/ConvertRestApiPostToWPPost', [$this, 'addParentToPost'], 10, 3);
add_filter('Municipio/Content/ResourceFromApi/ConvertRestApiPostToWPPost', [$this, 'addParentToPost'], 10, 3);
}

public function preLoadAcfValue($value, $postId, $field)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ private static function convertRestApiPostToWPPost(stdClass $restApiPost, object
$wpPost->comment_count = 0;
$wpPost->filter = 'raw';

return apply_filters('Municipio/Content/ResourceFromApi/ConvertRestApiPostToWPPost', $wpPost, $restApiPost, $localPostType);
$wpPost = apply_filters('Municipio/Content/ResourceFromApi/ConvertRestApiPostToWPPost', $wpPost, $restApiPost, $localPostType);

if (is_a($wpPost, 'WP_Post')) {
wp_cache_add($wpPost->ID, $wpPost, 'posts');
}

return $wpPost;
}
}

0 comments on commit 6b72de2

Please sign in to comment.