pre_get_posts causings DB error when using ( ‘posts_per_page’, -1)?
pre_get_posts causings DB error when using ( ‘posts_per_page’, -1)?
pre_get_posts causings DB error when using ( ‘posts_per_page’, -1)?
Try this: function exclude_single_posts_cat($query) { if ( is_admin() || ! $query->is_main_query() ) return; if ( $query->is_archive() ) { $query->set(‘post__not_in’, array(‘1′,’2′,’3’)); } } add_action(‘pre_get_posts’, ‘exclude_single_posts_cat’); Issue: The issue in your first approach is you have added extra curly brackets and comma.
The way to go is apply custom filters to the WP_Query you are running. add_filter(‘posts_clauses’, function ($clauses, $query) { global $wpdb; // only run the filter for a given query // do your checks and return early if (!$query->is_main_query() || !$query->is_post_type_archive(‘tracklist’)) { return $clauses; } $clauses[‘fields’] .= “, COUNT(items.id) AS track_count”; $clauses[‘join’] .= ” LEFT … Read more
function exclude_product_category( $query ) { if ($query->is_search()) { $tax_query = (array) $query->get(‘tax_query’); $tax_query[] = array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => array(‘excluded-category’), ‘operator’ => ‘NOT IN’ ); $query->set(‘tax_query’, $tax_query); } return $query; }
I believe with the help of remove_post_type_support you can achieve this. But first you need to keep an user meta with the list of posts IDs he/she will be able to edit. And you can achieve this with this below function- update_user_meta( $user_id, $meta_key, $meta_value, $prev_value ) So whenever a post will be loaded you … Read more
No you can’t pass a callback function. Callback functions are PHP, so they can’t be run in MySQL. For that to work it would need to query the results from the database first, but you’d get the wrong results because they’re unsorted. You would need to use the posts_orderby filter to do this as part … Read more
The pre_get_posts function is a simple query modifier for general “post” queries. If you’re looking to modify the SQL directly for these query I suggest using the post_clauses hook. This hook passes an array of SQL clauses such as: $sql[‘where’] and sql[‘join’] Here you can inject your own custom SQL into the specific clauses. That … Read more
How do I troubleshoot pre_get_posts with Debug Bar?
Random order not working correctly when using default loop + $query->set
meta_query is overriding default search