How to exclude homepage from query
-
Hi all,
I’ve been building this beautiful website with the fukasawa theme. The menu consists of 27 category items (an alphabet, you see) and I managed to create a simple query to have each of those pages sort the items alphabetically on title.
The problem is, I want the homepage to show the most recent additions – preferably limited to 20 or 30 items, instead of “all items” which is on those category pages.Could you help refining this query? I am a total novice with php so I guess I need help.
The current code, added to my functions.php, is:
add_action( 'pre_get_posts', 'x_category_order' ); function x_category_order($query){ if(!$query->is_main_query()) return $query; if(is_category( array( 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ) )) $query->set( 'orderby', 'title' );$query->set( 'order', 'ASC' ); return $query; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How to exclude homepage from query’ is closed to new replies.