So I got this to work by adding this function to functions.php
// Custom query for events
function set_posts_per_page_for_events_cpt( $query ) {
if ( !is_admin() && $query->is_main_query() && is_post_type_archive( 'events' ) ) {
// set date
$currentdate = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
$meta_query = array(
array(
'key'=>'event_date',
'compare' => '>=',
'value'=> $currentdate,
'type' => 'DATE',
),
);
$query->set('meta_query', $meta_query);
$query->set( 'posts_per_page', '12' );
$query->set( 'meta_key', 'event_date' );
$query->set( 'orderby', 'meta_value' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'set_posts_per_page_for_events_cpt' );
Related Posts:
- paginate_links() don’t properly work in search.php?
- How to paginate the get_users function?
- Pagination adding page-numbers dots when using ‘mid_size’ => 0
- Change number of posts to show on Archive page (custom post type)
- Paged Single Post doesn’t redirect to the main url after Removing Pagination
- mysql custom wp query
- How to style current page number (wp_link_pages)?
- WordPress – thumbnail image from youtube (function and loop)
- Customize “the_posts_pagination” and put list instead div
- Find first image on paginated post for Pinterest
- Post Pagination Showing Same Posts Every Page
- Generating rel=prev and rel=next only on wordpress categories
- Shortcode pagination not advancing
- Wp_query function to search from product_title ‘OR’ product tags name
- Get Current Post ID in functions php, meta query filter
- show first 3 thumbnails of posts in different sizes [closed]
- get_next_posts_link not working without parameter max_num_pages
- meta tags doesnt fetch data from permalinks
- Pagination in relation to archive.php
- paginate_links() don’t properly work in search.php?
- Exclude from the query posts with meta_key and meta_value
- How to obtain the recent posts without their content in an efficient way?
- the_posts_pagination() function returns missing page numbering on some blog pages
- Custom Query Not Paginating
- Where to call my pagination function?
- Remove ‘page-numbers’ class from prev and next tags
- How to display the_archive_title() and the_archive_description() – “weird” interaction
- Modifying the_posts_pagination from within functions.php instead of template files
- Using functions.php to include code that’s processed inline
- Getting images from media library and get_the_date() not working
- Unable to Change “Pages:” Before WP_LINK_PAGES
- Detect Ajax call inside pre_get_posts function
- How do I make a custom “Read More Blogs” button for my blog page
- I want to customize the_posts_navigation function by replacing prev and next with images
- Shortcode with pagination advancing multiple queries
- Pagination won’t work on custom page
- Remove post from latest posts after a month only with certain tag
- Display page number on custom page title function
- How to exclude posts with empty and non-existent relational custom field with meta_query?
- WordPress not showing pagination links
- Pagination in Search result
- Pagination fault in custom post type archive page [duplicate]
- List Most Read Posts from last 7 days (with custom post type and other meta queries)
- Adding pagination to custom WordPress function
- Modifying Page-Links format
- Integrating custom API for post content into Admin interface & Public Website [closed]
- WordPress is adding pagination for all pages not only for blog page, How to remove pagination for all pages except blog/posts page?
- Insert image between X number of posts but on specific paginated pages?
- /page/2/ redirect to 404
- Missing feature image link function
- What’s the difference between home_url() and site_url()
- Remove “Category:”, “Tag:”, “Author:” from the_archive_title
- get_template_directory_uri pointing to parent theme not child theme
- How to customize the_archive_title()?
- remove empty paragraphs from the_content?
- What is the “with_front” rewrite key?
- Why use if function_exists?
- How to override parent functions in child themes?
- Nested meta_query with multiple relation keys
- wp_enqueue_script was called incorrectly
- Add multiple custom fields to the general settings page
- Ajax call always returns 0
- 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
- How long does a deprecated function live in core?
- Solution to render Shortcodes in Admin Editor
- How to add a data attribute to a WordPress menu item
- What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
- remove_action on after_setup_theme not working from child theme
- plugins_url vs plugin_dir_url
- Remove type attribute from script and style tags added by WordPress
- How to run a function every 5 minutes?
- How to use a custom post type archive as front page?
- Best way of passing PHP variable between partials?
- Upload Multiple Files With media_handle_upload
- How to display custom field in woocommerce orders in admin panel?
- Adding fields to the “Add New User” screen in the dashboard
- Issues with title-tag and document_title_parts
- How do I get the current edit page ID in the admin?
- How to check if a user exists by a given id
- Why isn’t is_page working when I put it in the functions.php file?
- Add tags to the section via functions.php
- Add image size if page template
- How to create a custom order status in woocommerce!
- Remove Actions/Filters added via Anonymous Functions
- Adding a second email address to a completed order in WooCommerce [closed]
- How to load parent_theme functions.php before child_theme?
- How to load scripts/styles specific for a page
- Programatically add options to “add new” custom field dropdown
- Is there any global functions.php file which works for any theme?
- Excluding iPad from wp_is_mobile
- When should you, and when should you not, use wp_list_pluck()?
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- Difference between the_permalink() and get_permalink() function
- What’s the difference between WordPress random_int() and PHP built-in function random_int()?
- Child theme – Overriding ‘require_once’ in functions.php
- Using meta_query, how can i filter by a custom field and order by another one?
- Link to user’s profile settings page?
- WordPress Enqueue for homepage only, functions.php, wp-framework
- get php variable from functions php and echo it in theme template files [closed]