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
- pre get posts not working with Tribe Events
- How can I create a meta_query with an array as meta_field?
- Query multiple meta key values?
- Differences between wpdb->get_results() and wpdb->query()
- Using WordPress public query variables
- wpdb get posts by taxonomy SQL
- How to List Events by Year and Month Using Advanced Custom Fields?
- Is there any difference between hooks posts_where with posts_join and posts_search performance wise?
- pre_get_posts with get_posts
- Remove [gallery] shortcode altogether
- Get a user’s most recent post title
- Different Main Navigation per category
- Show recent products first but “sold out last” in query
- Show All Posts Insert Edit Link
- Get IDs of posts currently visible on archive
- Get posts by category with pure SQL query
- can’t get query to order posts by acf datepicker
- Custom query to get terms from post ids
- Help with wordpress custom query and advanced custom fields plugin
- WordPress query by category, sorted by custom field
- Mysql / WordPress killing my server with 80k users [closed]
- Query all posts and not repeat the same tag
- Deleting data from a custom table in WordPress
- How many queries are normal to execute on a WP site?
- How to optimize my query filtering out unwanted data?
- Remove posts from query for events whose start date has passed
- Insert static element only once in query archive
- How to run a mysql query when admin updates user role?
- Error when using setup_postdata()
- Getting post data from private page
- Missing posts in a query
- Alter a specific query on WordPress
- SQL query to select posts from multiple categories
- Why a URL with a query is always slower than that without a query?
- Maintaining Queries in URL
- Protect sequence of pages with same password for each of two groups of users
- How is it possible to get top comment from all children?
- Select Query demand excesive resources [closed]
- Create Indexes for Slow Queries
- Query to get number of posts last week
- How to write: $wpdb->update having WHERE NOT value pair in the array
- Exclude all sticky posts front page twenty twelve
- Query returning same results even though the ID changes
- 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?
- modifying main query to query for ranges e.g. from 1999 to 2016
- Using cron for multiple queries
- very slow wordpress query with default query
- Custom Query problem access the values
- Exclude sticky posts from query
- 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?
- Sorting a custom post type in pre_get_posts
- How to show sticky posts on all pages of the pagination, not just the first page?
- Why does $_GET return values but get_query_var does not?
- Sort users in admin screen by meta value whether it exists or not