Why reinvent the wheel? Just create archive-{posttype}.php
, and ensure that 'has_archive'
is set to true
for the post type.
If your post type is event
: archive-event.php
.
Then, WordPress will handle the query automatically. If pretty permalinks are enabled:
example.com/{posttype}
…will display the archive index page for {posttype}
.
Related Posts:
- How to get all author posts outside of author templates
- How to display last whole post on the homepage
- WooCommerce – Print Processing orders [closed]
- How to securely provide a $_POST var in WP_Query with PHP 7?
- Using foreach loop breaks
- Create WP_Query to search for posts by their categories or their parent/child categories
- WP Query with custom Shortcode
- wp_query with cat not working
- how could I load a different template part by page
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- How to use an associative array in post__in with WP_Query?
- creating a second image attachment template?
- If Query In Sidebar
- Recent Posts slider, using WP_Query(), loads duplicate sliders
- Compare post-IDs within WP_Query? (Less than / Greater than)
- Mass update excerpt
- How can I get a single php file that is the equivalent of an existing WordPress page?
- How to use $query->set with post__in?
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Get and insert order email address to the PHP template inside HTML text
- Custom search results page not working with empty search
- Loading the same WP_Query in two different wordpress .php templates
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- How to prevent WP_Query function from returning all posts when empty?
- How to show single category archive
- Dynamic content based on a URL parameter
- Display a specific category of products in shop page and disable code for specific actions
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- code is skipping a div
- Issues getting PHP to display in category pages
- Add more button if more 8 items
- How to store post ID’s in cookie or session to display the same posts later
- WordPress, AJAX and pre_get_posts using conditional tags
- Get users that likes the post
- Change title only in dynamic page
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- Exclude posts based on meta value
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Secondary navigation menu on one page
- Enable custom logo upload if logo is not in header
- Custom query, checking values of multiple meta keys
- auto-populating custom nav with all items from custom post type
- inserting a post from an extern php file but post content doesn’t show on wp site
- Remove echo from shortcode
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- How can I edit the content in index.php? [duplicate]
- WordPress theme options error
- Woocommerce Show Single Product on Homepage
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- how to show only specific category for a template
- Show a different code on front page to other pages
- Does wordpress templates always in files or in database?
- Security for data obtained from the database
- Fatal error: Call to a member function query() on a non-object
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Using same variable names in files added with get_template_part()
- Get posts from multiple post type
- PHP include is only working in certain places in my custom WP theme
- Use WordPress function in php file
- Is it possible to retrieve all posts with a certain value for metadata?
- Adding wrapper elements in the_date() like in the_title()?
- WP_Query fails despite having 1 post
- Add filter multiple times using only one master function
- Showing latest post without 301 redirect
- unable to use ‘new WP_Query’ in AJAX call
- WordPress template page name displayed on screen
- Is there a way to hook or call a custom woocomerce template that is not part of the default templates of woocommerce?
- wp_query get the 2nd post
- Exclude posts with specific metadata from search?
- How to get post ID in a Page?
- Display an image if odd number of posts in grid
- single.php with different look by category
- How to retrieve the data from the sever and displaying it in a page?
- How to call multiple functions from multiple files into a WordPress page template [closed]
- How to add div blocks after certain set of post
- How to overwrite orderby with add_query_var
- How do I define a lookup table that will work across all PHP elements of the template?
- persist a variable set in header.php all the way down to footer.php
- Function Reference Documenting Template Tags for use in Custom Theme Templates?
- Why doesn’t PhotoSmash plugin play well with wp_query?
- Removing WordPress Footer -without access to PHP code?
- How to set a template with wp_insert_post
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- get_the_ID() in the footer returns wrong value
- Trouble inputting variable into WP query
- the_posts_pagination() not working in wpquery
- Why does the Woocommerce grouped template prints the unpublished products?
- Adding conditional text to a PHP Shortcode Template
- Create page template via functions.php?
- How to override url params with rewrite rules vars?
- WP_Query: getting posts where custom field exists
- How to show meta value code HTML after x paragraph
- Form search query – displaying ACF “Post Object” field as results
- What’s a good way to allow overwriting files within a child theme if I want the same folder structure?
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- Convert a string into a decimal number for use in query
- How to display SQL query that ran in WC_Order_Query?
- get_the_ID() doesnt work
- Array to string conversion on array_map
- Store metakey value as an array