Jetpack Infinite scroll conflicting with theme’s pre_get_posts custom posts_per_page

You’ve specified a priority of 1 for your pre_get_posts function here: add_action( ‘pre_get_posts’, ‘mytheme_portfolio_archive_pages’, 1 ); Jetpack doesn’t specify a priority: add_action( ‘pre_get_posts’, array( $this, ‘posts_per_page_query’ ) ); So that gets added with the default priority for add_action, which is 10: $priority (int) (optional) Used to specify the order in which the functions associated with … Read more

Modify query in pre_get_posts action is messing up my nav menu

pre_get_posts runs for every query. That includes the main query, secondary queries, and menus. The problem is that is_post_type_archive(array(‘provider’)) is checking if the main query is the post type archive, not a specific query going through pre_get_posts. So when you check for that and then modify the current query going through pre_get_posts you’re going to … Read more

order by multiple meta keys in pre_get_posts

Maybe a bit late … add_action( ‘pre_get_posts’, function($query) { if ( !is_admin() && $query->is_main_query() && is_post_type_archive( ‘[your_post_type]’ ) ) { $query->set(‘meta_query’, array( ‘_property_price’ => array( ‘key’ => ‘_property_price’, ), ‘_property_featured’ => array( ‘key’ => ‘_property_featured’, ) )); $query->set(‘orderby’,array( ‘_property_price’ => ‘DESC’, ‘_property_featured’ => ‘DESC’ )); } return $query; } );

pre get posts changing the query

Try using meta_query parameter : add_action(‘pre_get_posts’, ‘add_event_date_criteria’); function add_event_date_criteria(&$query) { // We only want to filter on “public” pages // You can add other selections, like here: // – Only on a term page for our custom taxonomy if (!is_admin() && is_tax(‘event-tag’) || is_tax(‘event-category’)) { $time = time(); $meta = array( array( ‘key’ => ‘start_time’, … Read more

How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?

pre_get_posts is executed before each and every query. Your $query->is_main_query() is making this code change the query only for the Main query. So, if you’re in an archive page, you’re modifying only the archive posts, and not any of the others queries (widgets, menus, etc). But be aware, that code you added there will change … Read more

Exclude a WordPress post from pre_get_posts if a field is null

@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’ ) … Read more

pre_get_posts with WooCommerce Shortcode Query

You could use the WooCommerce filter woocommerce_shortcode_products_query to change/manipulate the query arguments. This example comes from the shortcode documentation. When using the Products shortcode, you can choose to order products by the pre-defined values above. You can also sort products by custom meta fields using the code below (in this example we order product by … Read more

Custom post type with tags

Yes, both assignments do the same, but the post_tag archive is using the post type post only by default. Don’t worry, there is a hook for you: pre_get_posts. Example with tags for pages: // register tags for pages add_action( ‘wp_loaded’, ‘wpse_75297_register_tags_for_pages’ ); function wpse_75297_register_tags_for_pages() { register_taxonomy_for_object_type( ‘post_tag’, ‘page’ ); } // add post type ‘page’ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)