You’re missing an s.
$query->set('posts_per_page', '1');
However – you probably don’t want to do this for every query, since that affects everything – widgets, back end, everything. You should make it conditional. For example:
<?php
function university_adjust_queries($query) {
// If this is the main query, not in wp-admin, and this is the homepage
if($query->is_main_query() && !is_admin() && $query->is_home()) {
$query->set('posts_per_page', '1');
}
}
add_action('pre_get_posts', 'university_adjust_queries');
?>
This will make sure you’re only affecting the main query (The Loop) on the homepage, and only on the front end. You can adjust the condition to target whichever spot you’re wanting to affect.
Related Posts:
- Custom query filter not working on woocommerce category page
- $query->query_var[‘post_type’] not set for pages
- Filter query posts by the count of metas for a meta key
- How to set back query var author_name after unset it?
- Change searched term
- pre_get_posts : ‘post__not_in’ doesn’t work with global variable
- How to reset usual $query on search page to push custom $wpdb query there?
- Merge CPT Taxonomy and Post Taxonomy in $query->set
- custom sorting media with multiple filters – error: not unique table/alias: wp_postmeta
- New custom post type entries are not sorted correctly in admin using pre_get_posts
- Limiting a filtered query
- Why the pre_get_posts hook can cause apache stopped working?
- excludeCat function reverses order of blog posts
- Run search query again without pagination gives no results?
- Set posts per page for parent category and it’s all children
- Filter multiple different main queries on custom pages
- Modify a query using both a text field and a true/false AFC field
- Admin Post List table Query filtering “WHERE” for custom post type
- How to Optimize WP site for millions of posts
- Get Terms by IDs with IDs order
- wpdb get posts by taxonomy SQL
- How many WordPress SQL Queries per page?
- Slow wp_enqueue_media()
- Advanced Custom Fields – Query Efficiency
- How to display lastest post date in the homepage?
- Get a user’s most recent post title
- Different Main Navigation per category
- Can not switch the queried post in pre_get_posts hook
- How to tell if $query_var isset?
- Show All Posts Insert Edit Link
- Sorting Grids with Essential Grid and Events Manger
- The use of including upgrade.php when building custom queries
- Get the timout value of a saved transient?
- Help with wordpress custom query and advanced custom fields plugin
- Does meta_query work within get_posts array?
- Mysql / WordPress killing my server with 80k users [closed]
- Slow meta_query with about 4 milion record on wp_postmeta
- How to show more than 5 posts?
- WordPress Find Duplicate Post By Content
- WP Query Sort by meta value (date)
- mySQL query. ORDER BY meta_key
- how to query multiple categories in wordpress?
- Disable the MySQL query in the main query
- Strange string in console from wpdb query
- Update slug (URL) of pending posts via phpMyAdmin
- How can I get the query that would be run for the archive page?
- Query metas (and not : query posts by metas)
- Select query for a login
- What’s wrong with my $wpdb prepare?
- where should I reset query after using get_results?
- Alter a specific query on WordPress
- Exclude featured image and custom field from this get_attachment query
- How is it possible to get top comment from all children?
- wpdb print all post meta
- Form and custom query problem
- Export Specific User data without plugin
- How to write: $wpdb->update having WHERE NOT value pair in the array
- Exclude all sticky posts front page twenty twelve
- All in One Calendar Plugin Custom Post Type Query [closed]
- Get Posts from Last 24 hours and Sort them via GD Star Rating
- Query returning same results even though the ID changes
- How to get events using multiple custom meta fields?
- Why my query ‘REPLACE INTO…’ does not work?
- Restrict query to last day with posts
- Custom query object with Simple-Fields custom date field
- How to read the value of a WordPress $query associative array (hash) key
- Query posts based on previous query
- Waypoints + infinite scroll with custom query
- Customizing the_tags output?
- Querying with WP query using meta key price
- Re-sort get_posts query results
- How do I get all results from my query
- Taxonomy filter under Polylang
- How to create an overview of posts with the same tag?
- create a link to a random post within the current category
- Pagination not working on custom post types with rewrite slug
- `offset` WP_Query argument dont work via `pre_get_posts`
- JetEngine Query Builder – order by value from repeater
- Change pure SQL database query to WordPress post query?
- Filter orders by modify date
- How to add url parameter to every search query in SearchWp?
- Heavy meta query causing SQL crash
- Sort by postmeta on when searching
- Pulling an ACF into a query
- Speed up search query that searches in post meta?
- Using cron for multiple queries
- very slow wordpress query with default query
- Sort loop with query in the link
- Custom Query problem access the values
- Exclude sticky posts from query
- list or get meta_key where meta_value is ‘something’
- If more than 1 image show post link?
- Rewrite Query_Var URL Parameter with Slug
- How to query different categories on index?
- How to specify what kind of is_single post?
- Can’t See Media Queries with Inspect Tool [closed]
- Print data from wordpress sql query
- Can I create my own query in wordpress with traditional methods?
- Query filter on custom post by current author in post widget for elementor query id
- Querying Posts from ACF Repeater Subfield Select Value