@Howdy_McGee – Thanks for pointing me in the right direction. Below is the code I used. By the way, I know that the FacetWP plugin can be a little particular with queries. In case anyone is wondering, this works with it.
function set_posts_per_page_for_attorneys_cpt( $atty ) {
if ( !is_admin() && $atty->is_main_query() && is_post_type_archive( 'attorneys' ) ) {
$meta_query = array(array(
'key'=>'last_name',
));
$meta_query = $atty->get('meta_query');
//filter out people without a particular key
$meta_query = array(array(
'key'=>'title_group',
'value'=>'',
'compare'=>'!=',
));
//update the query
$atty->set( 'orderby', $meta_key);
$atty->set( 'order', 'ASC' );
$atty->set( 'meta_query',$meta_query );
$atty->set( 'posts_per_page', '-1' );
$atty->set( 'facetwp', true);
}
}
add_action( 'pre_get_posts', 'set_posts_per_page_for_attorneys_cpt' );
Related Posts:
- Sticky Posts exceed posts per page limit
- Theres a way to use $query->set(‘tax_query’ in pre_get_posts filter?
- Modify Taxonomy pages to exclude items in child taxonomies
- Obliterate the main query and replace it
- Post injection – how to exclude the original post
- Adding meta_key via pre_get_posts causes navigation to disappear
- Sorting posts that has a meta value first then the rest of the posts
- pre_get_posts on a page
- How pre_get_posts filter by roles in WP Admin
- Weird problem with pre_get_posts and $query->is_page()
- Why is ‘pre_get_posts’ having no effect?
- Date Query to Pull Current and Future Posts
- pre_get_posts all posts and custom post type with certain tag
- Using Sessions to Filter Posts – bad thing?
- pre_get_posts and the blog page
- Archive by custom post type and custom date field
- pre_get_post filter returns results when there should not be
- Trying to exclude first 5 posts from the first page on the homepage
- Why the ‘date_query’ is not working in ‘pre_get_posts’ hook?
- Only show certain post types in recent posts widget
- pre_get_posts for exclude category
- pre_get_posts: using tax_query only for certain post type
- pre_get_posts dont firing… Anybody knows whats the wrong with my code?
- Restrict Search Query To After Specific Date
- WP_Error not displaying errors
- Show all posts even if URL points to a single one
- How to achieve post_status__not_in?
- Ordering by meta_key
- Using a pre_get_posts filter to search for multiple strings on all meta values
- Removing taxonomy query by pre_get_posts
- Using different parameters for different queries with pre get posts in functions.php
- how to restrict posts_request filter to the main query only
- Automatically applying a pre_get_posts filter for child categories only
- How to override a query and display specific page by ID?
- pre_get_posts variables
- Another query in pre_get_post cause memory issue
- pre_get_posts having no effect on my category archive
- pre_get_posts returns non property object when using posts__not_in
- Override tax_query with pre_get_posts to include other term_ids on a single category
- $query->is_main_query() is causing query’s tax_query to be ignored
- Menu disappears when meta_key changed [closed]
- pre_get_posts with multiple queries
- How to show the last and newest modified post in a custom category?
- Altering the main query using get_post_meta() in pre_get_posts
- Why query by specific date with variables doesn’t return same result that with harcoded integers?
- Sort WordPress Archive by multiple oderby arguments in pre_get_posts action
- Exclude post type with pre_get_posts?
- Exclude page by title for non admins
- problem with setting tax_query in pre_get_posts
- Problem ID to exclude specific posts from category
- Modify Taxonomy pages to exclude items in child taxonomies
- Modify author archive query to combine two queries
- Change post order on archive to be displayed by most commented being ignored by theme
- Complex query using pre_get_posts
- Super confusing ‘pre_get_posts’ behavior with $query->set
- Having trouble with settings terms as array in pre_get_posts
- Override main query for page template
- Querying custom taxonomy on category-specific page is overwritten by function
- how to get content from other site and show it?
- Insert a variable in pre_get_posts
- Extend taxonomy term page with other posts
- Set a custom number of posts on the first page
- Why does this query not SELECT post IDs like a normal query would?
- Please ensure me that I’m not crazy using the pre_get_posts [closed]
- How to pass >= condition filter to my year custom tax_query
- What is the proper way to use pre_get_post?
- pre_get_posts has php notice when not on CPT archive
- Duplicating event posts in wordpress
- Show only posts which can be commented OR have custom meta field
- How to show more posts on an archive page?
- SQL Statement generated by WP_Query not producing expected results
- Conditional tag for all categories of a custom post type
- Can’t sort order of wp_query with 2 meta keys
- Using meta_query and custom fields within pre_get_posts to return posts within a numerical range
- How to set back query var author_name after unset it?
- Search function works improperly
- Store sticky post’s ids in a transient
- Using meta_query with multiple keys and compare values
- Can I set my WP_Query to be a Main Query?
- Exclude post by custom meta with pre_get_posts
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- Main menu not appearing in custom post type archive
- why pre_get_posts works fine in post type archive, but not in search result list?
- Sorting search results with custom dropdown
- How to display custom post type?
- WP_Query, Paginate by Custom Field
- Exclude taxonomy Query if post_type
- How do I display main query posts in random order using add_filter
- Block internal search queries with pre_get_posts and regex rules
- is_user_logged_in not working from WP-API (wp-json)
- Search Exact on WordPress – Relevannsi Solution Not Working
- How do I troubleshoot pre_get_posts with Debug Bar?
- How to offset main query without affecting other queries and backend
- Testing requested query in pre_get_posts
- Modify query to exclude certain ids and certain parents and its corresponding children
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- Get query result before posts are displayed?
- Custom post types loop on a page template
- pre_get_posts returning unformatted page
- Custom taxonomy with custom meta value is not sorting correctly (query returns the same value for orderby regardless of sort column click)