Please thoroughly read the WP_Query
docs, especially that part about post types. Means you need to pass the query the post type you want to query:
$args = array(
'post_type' => 'my_custom_post_type',
'posts_per_page' => 1,
);
$query = new WP_Query( $args );
Even better it would be to simply override the existing query for that archive page by hooking into pre_get_posts
. This will for example also adjust the pagination accordingly. Place this in your functions.php
:
/**
* Override the main query on a custom post type archive.
*
* @param \WP_Query $wp_query
*/
function wpse_337567( WP_Query $wp_query ) {
// Only check this on the main query.
if ( $wp_query->is_main_query() && is_post_type_archive( 'my_custom_post_type' ) && !is_admin() ) {
$query->set( 'posts_per_page', 1 );
}
}
add_action( 'pre_get_posts', 'wpse_337567' );
Related Posts:
- How to retrieve all post titles of a specific post type?
- How to use a custom post type as front page?
- How to order custom post type by multiple custom fields?
- Sort Order for a Custom Query in a Post Type Archive Not Working
- Custom Taxonomy with Custom Post Type Finds No Posts
- Display several random posts, but make sure a condition is met
- How can I generate a RSS feed based on a custom WP_Query?
- Custom query – alternate posts by category
- Search Custom Post Type with all meta attached?
- Query by 2 values of a repeater ACF field
- Custom post type loop split/ordered by taxonomy
- Display two post types ordered by two custom fields
- Display children and grandchildren of a custom post type
- Getting all custom posts with a certain category
- Sort by two dates. Default entry date and custom field if present
- Querying CPT with Two Taxonomies
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Custom Query to display posts with custom field
- Get taxonomy description based on variable
- Custom post_type search’s $wp_query->query_vars do not correspond
- wp_query custom post type by taxonomy & standard post by taxonomy
- Query Custom Post Types & category_name?
- Conditional to modify query results
- WP_Query is printing out only one post when posts_per_page is set to multiple
- WP Query to displaying date and posts for that date?
- Use get_post_types to query only custom posts types
- Use WP_Query() to Output the 4th to 6th Most Recent Posts of a Custom Post Type
- Get all Posts If has same custom field values in Posts
- Custom Post Types not showing, custom WP_Query
- WP_Query | ‘post_type’ doesn’t work
- Filter by custom taxonomy slug on a custom post type
- Sorting multiple custom post types without a meta key/value pair by sort order
- Pagination : How to remove /page/x/ after a ‘POST’ action on a form returning to page 1
- Can I create a loop with multiple post types and specify different $args for each post type?
- Display custom post type from dynamic custom field
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- wp_query check if integer exists in custom field’s array
- Previous/Next Link by Meta Value in CPT
- Custom-Posttype & Custom Taxonomy WP_Query
- orderby rand is not working for a custom post types
- Stuck in Order by more then one
- Display featured image from one CPT within another CPT query
- What’s the WP way to load remaining custom posts?
- Several post types on WP Query by tag and taxonomy
- Filter Posts from the Main Query
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- How can I group posts by months and years?
- Display post from a date range from custom field
- Displaying a div from an assigned meta_value when on a page
- Creating two loops based on different logic
- Retrieving meta-box from a custom-post-type
- Getting a custom post’s custom field based on another custom post’s custom field select
- Custom post type loop with custom category filtering
- Show message when query has no posts
- How to show all taxonomies within custom post type loop
- WP_Query not resetting after wp_reset_postdata
- Custom post type to lead to single post type instead of shortcode modal
- Filter posts of custom post type by meta key in (List All Section)
- Query Posts that have Custom Taxonomy
- Display post from custom post type
- Query Posts, order by meta value
- Foreach loop returning more than one item when querying taxonomy
- how to compare different timestamps in wp-query for events custom post types?
- Is there a (preferable built-in) way to check what custom queries are used in a theme?
- Sorting the Loop by Taxonomy Value
- Previous / Next Links For Custom Post Type Sorted By Meta_Value
- Custom Query: Multiple CPTs and a taxonomy filter
- Ordering by meta value not working
- Custom wp-query display post only today
- Create if else for post types in WP_Query ‘post__in’ values
- Custom post type query with taxonomy
- Display Custom Post Type Based on Taxonomy With WP_Query()
- Search Function not searching correct custom_post_type even though post_type is defined in search args
- 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 to use multiple orderby conditions on query search results? (orderby one post type, relevance)
- Query a custom taxonomy in a function to create an csv file
- Custom Post By Category
- Mix Facebook and Twitter feed into custom posts
- pre_get_posts gives 404 error on Custom Post
- Query for a custom post taxonomy
- Get post from Category by Priority
- WordPress loop multiple orderby query with Types toolset
- Strange behavior on WP_query
- Get posts associated with custom taxonomy alternate way
- Calling specific page with wp query
- display news with pictures 3 small and one large (loop)
- tax_query showing no results
- Can’t use orderby in WP_Query
- Custom post type blog pagination conflict
- Custom post type pagination, single page issue
- How to display elements of different post types?
- display post types alternately
- Trying to combine multiple WordPress queries
- Cannot query custom post type taxonomy from theme options array
- Query Custom Post Type by Tag
- How to store queried custom data and use it in multiple pages?
- Adding custom shortcode to page leads to page without styling
- Attaching multiple custom taxonomies to one CPT?
- WP_Query() displaying past post / event
- WP Query Conditionally query meta and taxonomy