number_posts
is not a valid parameter in pre_get_posts
, you should be using posts_per_page
You should also include a check (!is_admin()
) in your query to check whether you are on the front end or back end as pre_get_posts
alters back end queries as well
Rewrite your code to the following:
add_action( 'pre_get_posts', function ( $query )
{
if ( !is_admin()
&& $query->is_main_query()
&& $query->is_tax()
) {
$query->set( 'posts_per_page', '20' );
$query->set( 'orderby', 'rand' );
}
});
Related Posts:
- Posts per Page on custom Taxonomy Template
- How do I query a custom post type with a custom taxonomy?
- Is it possible to have an index page for taxonomy term for each custom post type it is assigned to?
- How to get_queried_object on multiple objects?
- Custom Post Type / Taxonomy Slug / Post Title with post type archive
- how to group custom post type posts by custom taxonomy terms
- Hide child term posts on parent term pages
- Post type archive page not working
- How to get the parent’s taxonomy?
- Query posts by custom post type and custom taxonomy
- List all posts in Custom Post Type but group dynamically by Custom Taxonomies
- Archive page for taxonomy of custom post type
- Should I change these content meta types before building complex archive page?
- Getting taxonomy terms used by custom post type
- Archive or taxonomy pages not working for custom post type
- How to get only one category of custom post type?
- Create Custom Post Type Archive Page with Sub Categories Navigation Sidebar
- pre get posts changing the query
- How to create archive page for taxonomy terms within custom post type
- Query for posts in 2 taxonomies
- How to make an archive page displaying posts in a date range
- Custom taxonomy template not working with simple loop. Multiple CPT using the same taxonomy
- ‘category__and’ for custom taxonomy?
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- How to dynamically build a multiple taxonomy query loop within a post type’s single loop?
- taxonomy template for custom post type the same as the archive
- Display only post types that are direct children of the current taxonomy
- How can I filter by taxonomy on a custom post type’s page?
- how can i get posts from custom post type particular taxonomy category
- Custom template won’t load for a custom post type (custom permalinks used)
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- Query/list all terms and their custom post count
- Archive for custom taxonomy lists all posts instead of current taxonomy
- Custom post type templating problem
- How to use custom taxonomies to reference complex relationships?
- Create template for taxonomy results limited by Custom Post Type
- Query Custom posts of same taxonomy as the post itself
- Extending AZIndex plugin to use custom post types and custom taxonomies
- Conditional Query of Custom Post Type and custom taxonomy
- Show a Category X’s custom post type on Category X archive page?
- Use Custom Post Type archive page for the taxonomies term archive page
- Display custom post type category, while in a CPT category, then the posts beneath
- Number of Custom Post Types published are not being shown in the custom page
- How to edit this code to get the categories in achieve page?
- posttype/taxonomy/term archive page 404 error
- Listing all term items alphabetically / sorting loop
- How to display Related Posts based on number of taxonomy terms matched
- Custom Post Archive is not working
- How to make WP_Query not to show irrelevant posts?
- What’s the name of the custom post type yearly archive template?
- Custom query – get_the_terms not work
- Control content before and after custom post type loop
- Custom post type, custom taxonomy, query posts only from taxonomy (children of)
- Display custom posts randomly in custom taxonomy archive
- Alphabetically sort a taxonomy.php template by post title
- Not able to export large no. of posts in csv
- attach CPT data to a taxonomy
- Custom Permalinks For CPT and pages with parent. Advanced WordPress
- Permalink problems with custom post type and custom taxonomy
- Targeting custom post type via functions.php doesn’t work
- sort CPT on Custom Taxonomy Archive page
- Use the custom post type archive for taxonomies?
- Custom Post type date archive for custom taxonomy
- Show categories of custom post type and not all posts
- Query Posts that have Custom Taxonomy
- List all posts in taxonomy term
- Custom Post Type Custom Archive Page Not Working
- Getting custom taxonomy posts on archive page
- Archive page for custom post type and custom taxonomy
- Query Multiple Custom Post Types & Exclude a Taxonomy Term
- Custom post type category permalinks and archive pages
- Displaying custom taxonomy menu in custom post type archive
- Sorting the Loop by Taxonomy Value
- Archive page of CPT’s custom Taxonomy
- Getting Same Description in All the Custom Taxonomy Posts
- custom post type and a “sticky” position taxonomy
- Displaying all posts by category and showing content on click
- pagination problem listing custom post types of taxonomy in wordpress
- Static Front Page not working for custom theme
- Building Link List for Custom Tax
- Custom taxonomy with custom post type archive page
- Custom Post Type / Taxonomy / Term – what template to use to avoid 404-page?
- Getting Custom Posts with Custom Taxonomy
- Custom post type post_type_link gives “page not found” on any other custom post type
- Custome post type “tags” pick default archive instead of custom post type archive
- Customize url from the_terms
- Custom post types not displaying per category
- Help with Multi Level Category Archive Page
- How do I get the posts from single page custom post type from a sidebar to display in a page?
- Custom post type archive page not showing on archive-posttype.php
- Custom taxonomy in custom post type archive with pagination
- WordPress custom post type
- Pagination fault in custom post type archive page [duplicate]
- Display 2nd category, only once, as sub-heading, in the loop
- Why is this custom post type defaulting to archive.php?
- title tag for custom post type remove taxonomy name from title tag
- Taxonomy Query of Custom Post Displays Archive Instead of Posts
- Custom taxonomy archive page not routing?
- Inserting two categories
- Custom Post Types using wrong template (index) instead of archive-{type}.php – previously worked as expected