You can use the Transients API to cache the entire HTML output so the queries are not done every time the page is loaded:
$transient="my-300-posts";
$timeout = 3600; // 1 hour
if ( false === $out = get_transient( $transient ) ) {
$args = array( YOUR ARGS GO HERE );
$posts = get_posts( $args );
if ( $posts ) {
foreach ( $posts as $post ) {
$out .= get_the_title( $post->ID );
$out .= // whatever else you want to output...
}
}
if ( $out ) {
set_transient( $transient, $out, $timeout );
}
}
echo $out;
However, you’re still serving 300 post thumbnails on one page load, which is a lot of data to transfer.
(You also need to delete the transient on the save_post
and delete_post
hooks)
Maybe you’d be better off with infinite scrolling? It’s an option in the Jetpack plugin.
Related Posts:
- How to show Y number of custom posts after every X normal posts?
- Display Authors Comments on Profile Page
- Custom Post Type Archive Page: Set Posts Per Page, Paginate
- Category as Class for Custom Post Type
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- Taxonomy posts on Archive page
- How to show related posts by category or custom post type?
- exclude custom post type by meta key in wp_query
- Posts navigation in custom post type single.php not working
- How to list custom post types?
- Unable to get post content from custom post type loop
- Display custom field of specific post where post title matches variable
- Remove duplicated values from a loop
- How to connect two custom post types with nested loops
- Normal pages as children of my Custom Post Type
- Creating select dropdown with parent-level custom post types
- Custom Post Type Loop throws 500 error when used in widget
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Group CPT posts by custom taxonomy
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Display Custom Taxonomy Alphabetically
- Problem: wp_query outputs all images on site
- The loop seems stuck to a single (now deleted) post
- Custom Post Types strange pagination problem
- Listing all term items alphabetically / sorting loop
- Display related custom taxonomy posts in sidebar
- Targeting custom post type
- Does WP have a global of $id?
- Conditional for a Single Post That Belongs to a Category?
- Bootstrap accordion looping through posts incorrectly
- Using wp_query to modify the loop in index.php for a CPT
- the_post() is printing titles in page footer
- Custom WP_Query doesn’t display all posts
- Query & the_content() is showing in the header
- Two column layout with alphabetical ordering
- Listing custom post types on archive page with array
- looping though custom post types and only return results in a given taxonomy
- How to conditionally add Custom Post Type to Front Page
- Dynamically insert code to custom post type loop
- Pagination not working on custom query on a page
- Search Filter CPT, Custom Loop
- Pull in taxonomy field of custom post type in new query
- get custom post type value in header.php [closed]
- Posts are not rendering perfectly [closed]
- get_terms() parent, child and grandchild
- Looping through custom taxonomy and display custom post types (Custom Post Type UI)
- pre_get_posts works in post type archive but not in single post
- Why is the output of a call to the_excerpt different when the call seems to be identical?
- Get post-meta value of all custom-posts – lowest to highest year-count?
- Custom PT, Taxonomys and wordpress query
- Only looping through pages that have children or subpages
- How can i loop through custom post type according to custom meta field?
- Custom Post Type Query W/Category Dropdown
- Changing WordPress sort order for returned child pages
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- On click some element i want to use some template
- How to Enable Ascending or Descending In WordPress Default Built-in Loop
- Fetch data from two custom post types and create multidimensional array for output to html table
- Page that lists publications by classifying them by taxonomy
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- How to display posts from a certain category in a bootstrap 5 carousel loop with multiple items?
- Exclude a specific post in a Custom Post Type
- Pin posts to top of custom loop
- Filtering posts based on three taxonomies
- Add extra elements to the_post in a custom post_type
- Accessing download link from the loop with WP Download Manager Pro
- Custom WordPress theme not displaying posts from category
- Custom Post Type has wrong label and is not found when called by a loop
- Combine multiple separate lists into one
- Error in the page of a CPT file in WordPress
- List all posts associated under custom taxonomy
- Custom taxonomy template for custom fields loop [closed]
- How to show terms used only for particular custom post type. Filter creation perpose
- How to prevent post to repeat on my loop?
- 2 custom posts types, in their own columns, one pagination for both
- Custom post type with custom taxonomy permalinks
- Pagination on custom post types
- How to get past and upcoming post by defining date in custom field?
- How to query all custom posts of a certain type and checking what category they have
- Post data in separate divs with incrementing class using WP_Query
- Redirection loop error after login from a custom post type post
- Load different template for CPT (in loop) in my plugin?
- How to loop custom post type posts by author?
- Custom loop won’t work, can’t find problem
- Categories and page filtering with pre_get_posts
- Loop through multiple custom taxonomy terms and display posts for a custom post type
- loop through custom post-type with two meta_keys
- Post_type doesn’t work for widgets?
- How do I correctly query posts from a post ID?
- display custom post type from register taxonomy
- How to exclude certain portfolios from a loop
- Custom post type and have_posts() return empty result
- why does my post loop break the page?
- display all posts in current category
- WordPress search results grouped by post type
- How to print different informations for different post types inside The Loop?
- WPNavi pagination links not working on custom pages
- Group search results by post type, but having a unique heading for each section?