template_include for search.php makes WordPress think its on the home page

Your problem is that you are not resetting all the needed query variables, like WP_Query::$is_page, WP_Query::$is_single and WP_Query::$is_archive. Also note that ‘pre_get_posts’ is fired for all queries, the main and the secondaries, so you should check that you are working on the main query. Finally, when you get data from $_GETyou should sanitize it before … Read more

Get user role by using user_id in buddypress

Try this function: function get_user_role($user_id){ global $wpdb; $user = get_userdata( $user_id ); $capabilities = $user->{$wpdb->prefix . ‘capabilities’}; if ( !isset( $wp_roles ) ){ $wp_roles = new WP_Roles(); } foreach ( $wp_roles->role_names as $role => $name ) { if ( array_key_exists( $role, $capabilities ) ) { return $role; } } return false; } I’ve not included … Read more

Complex Search functionality. Advice needed

There’s a few ways you could do this. I once wrote some extended code to integrate Apache Solr with WordPress search and BuddyPress and that added a lot of power. With something like Apache Solr you can customize weight and do some interesting things. Solr is a full fledged search engine and you will need … Read more

WordPress 3.6, searchform.php problems

The answer is taken from WordPress.org Support Forum thread: » 3.6 upgrade – searchform.php not working As salcode said: Adding this code to your functions.php should do the trick: function search_form_no_filters() { // look for local searchform template $search_form_template = locate_template( ‘searchform.php’ ); if ( ” !== $search_form_template ) { // searchform.php exists, remove all … Read more

Exclude top-level pages from search results

I wonder if this will work for you: function search_filter( $query ) { if( $query->is_search AND $query->is_main_query() ) { // $query->set( ‘post_parent__not_in’, array( 0 ) ); // We comment this out here $query->set( ‘post_type’, array( ‘post’, ‘page’ ) ); } return $query; } add_action( ‘pre_get_posts’, ‘search_filter’ ); and function wpse_120638( $where, $query ) { global … Read more

Let user change posts per page

This is may not be the best solution, but it works. Following code needs to be added in functions.php. add_filter(‘query_vars’, ‘parameter_queryvars’ ); // Let WP accept the query argument we will use function parameter_queryvars( $qvars ) { $qvars[] = ‘posts_per_page’; return $qvars; } add_action( ‘pre_get_posts’, ‘change_post_per_page’ ); // Filter posts based on passed query variable … Read more

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