pre_get_posts having no effect on my category archive

You’ve got a typo there, should be: is_admin(). You should enable debugging by setting define(‘WP_DEBUG’, true); in wp-config.php to see such errors. Also there’s no need of returning anything in action hook. add_action( ‘pre_get_posts’,’filter_archive’, 1 ); function filter_archive( $query ) { if ( ! is_admin() && is_category(’76’) && $query->is_main_query() ) $query->set(‘posts_per_page’, ’12’); } Sidenote: personally … Read more

How to reset usual $query on search page to push custom $wpdb query there?

This is not how pre_get_posts works. The pre_get_posts action gives developers access to the $query object by reference (any changes you make to $query are made directly to the original object – no return value is necessary). https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts What you are doing is simply wrong. You don’t “return” another query via pre_get_posts, you alter the … Read more

Search for two strings in WP search

I am not 100% sure what you are trying to accomplish, but you can “search for both strings” simply by concatenating them: function checkForAa($query){ if($query->is_search){ $search_string = $query->get( ‘s’ ); if( stripos( $search_string , ‘aa’ ) !== false){ $new_string = str_ireplace( ‘aa’ , ‘xxx’ , $search_string ); }elseif( stripos( $search_string , ‘å’ ) !== false){ … Read more

pre_get_posts – Trying to get property of non-object warning

$screen may not be available yet when pre_get_posts fires. Try this instead: public function my_post_type_default_sort( $query ){ if(!isset($_GET[‘orderby’]) && is_admin()) { $orderby = ‘0’; } if($query->is_main_query() && is_admin() && is_post_type_archive(‘my_post_type’) && $orderby=0) { $query->set(‘orderby’,’scr_date’); $query->set(‘order’, ‘ASC’); } }

pre_get_posts shows posts in random order sometimes

pre_get_posts is not a filter hook, it is an action. Also you should not set orderby to menu_order for posts as they are not hierarchical. Set orderby to date instead. function modify_query_amount_shown( $query ) { if ( $query->is_category ) { $query->set( ‘posts_per_page’, 30 ); $query->set( ‘orderby’, ‘date’ ); } } add_action( ‘pre_get_posts’, ‘modify_query_amount_shown’ ); Now … Read more

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