This code:
$term = get_term_by( 'slug', get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy']);
… just fetches the term data for the currently queried term, it’s not altering the query in any way.
To alter the query for your taxonomy term archives, you want to use the pre_get_posts
action. Altering the query in the template just creates a new query, overwriting the original, as the main query for all pages happens before the template is loaded. This code would go in your theme’s functions.php
or a custom plugin:
function wpa_alter_taxonomy_query( $query ) {
if ( is_tax( 'your-taxonomy' ) && is_main_query() )
$query->set( 'posts_per_page', -1 );
}
add_action( 'pre_get_posts', 'wpa_alter_taxonomy_query' );
just change 'your-taxonomy'
to the name of your taxonomy.
Related Posts:
- Help understand and create a loop with WP_query
- Use WP_query to match post types based on custom field values
- How select query is generated in a Custom Post Type?
- Filter posts by their related field’s custom field
- How to sort by multiple values in a nested WP_Query
- Custom post type category returns null
- wp_post_delete is deleting all offices
- SEARCH QUERIES – REVERSE OUTPUT
- Foreach result into WP_query
- How can I fetch all the dates from custom fields from various different custom post types and show / list them at one place in ascending order?
- How do I insert a custom post type query after a certain number of recent posts and then resume recent posts?
- Query custom post type and custom field by URL parameters
- WP_Query to display number of custom post type filtered (order by) taxonomy
- How can I get custom post types to recognize pretty permalink variables?
- WP_Query for custom taxonomies showing posts from non-specified terms?
- 2 modal windows with ACF content on Archive page
- Problems in paginate_links with custom query loop and MB-Relationships
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Error in the page of a CPT file in WordPress
- Query a Custom Post Type using SELECT that has ACF fields to compare dates
- meta query multiple values for the same key
- Tell wordpress to show a single page instead of an archive page
- How to display grandchildren only of custom post?
- How to get post by meta value
- Sort custom post archives by a meta value from a different custom post type?
- WordPress doesn’t respect Page slug in custom post type url pagination. Keeps getting removed
- post_type incorrect for custom post type
- Live search by custom tag
- how to display new private message to users?
- Custom Post Type – Display all, wrap in groups of 3
- Make pagination work as a carousel (custom query)
- WP_Query with all posts in one custom post type and only posts in another custom post type with a specific category
- Search result based on URL
- Staggering featured post using ‘sticky’
- How to use multiple orderby conditions on query search results? (orderby one post type, relevance)
- Custom post types – meta_query: search lesson which starts sooner
- Query a custom taxonomy in a function to create an csv file
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- Wp Query sort order from custom MetaBox
- Post Filtered by Custom Field Value
- How do I get all authors posts of a custom post type outside loop
- minimize wp_query call to database
- Output all terms slugs for a loop filter
- WP_Query based on ‘s’ and tax_queries
- subtracting the current post form then whole loop, which is generating all CPT titles
- Show specific posts with WP_Query using ACF Post object
- Filter custom WP_Query by first letter of a custom field – hopefully using Search and Filter Pro?
- WP_query sort by taxonomy
- Custom Taxonomy – fields
- WP Query filter search. Result show all posts instead just custom post type
- CPT Loop, include taxonomies and disclude others?
- post type => ‘any’ not applied my custom queries
- Custom Post By Category
- Ajax load more inside custom post type taxonomy
- Custom Post Type Query by user id
- Mix Facebook and Twitter feed into custom posts
- Post Query , breaks layout if a post is deleted
- sorting in wp query based on custom field value
- Query posts based on user preferences
- Custom post Query and WordPress Post Query Clash
- How to get the posts that my following users are liked?
- Meta_Query refuses to return results
- One of my headings is mysteriously coming up as a link in my CPT Archive
- Only show categories that have posts within custom post type
- Linking posts together with Advanced Custom Fields “both ways”
- Query the title of the page to show posts with matching category in the loop
- CPT post doesnt shows tags and category on backend admin page
- WP Query tax_query not returning posts
- Adding a nav menu for a custom post type
- Create a custom wp_query from a specific custom post type with specific taxonomy
- Not able to get my custom search result using meta_query and tax_query together?
- pre_get_posts gives 404 error on Custom Post
- Multiple WordPress Sites, Same Database but Filtered Content
- The most recent post of custom taxonomy
- Create Second Search Page Only for Custom Post Type
- Custom Field as Custom Post type element class
- Query for a custom post taxonomy
- Display posts on parent post if author coincides
- Display child posts from a certain category
- Display posts of a hierarchical custom post type excluding parent posts
- How to use costum database table for custom post type
- Why get_posts() returns empty array while I am trying to get posts from some specific taxonomies and work properly with others?
- Get post from Category by Priority
- Most efficient way of showing children posts?
- WordPress query in which condition uses custom field
- WordPress loop add heading before first of type
- WordPress loop multiple orderby query with Types toolset
- SQL LIKE in WP_Query
- Problems with the WP_Query query for a Custom post type
- How can you use a page for a custom post type?
- Only show current category post
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Displaying WordPress posts from post and custom post type in custom taxonomy
- How to get Current week and current date record wp query
- Display all Custom taxonomy terms and their relevant custom posts
- Error in WP Query. If variable is empty it is displaying previous post value
- How to get post meta for custom post type and taxonomy
- wp_query return nothing
- Querying, storing, and using data from 2 separate custom post types
- Strange behavior on WP_query