WordPress does not find author pages in search

I used this extra query in search.php: $search_string = esc_attr( trim( get_query_var(‘s’) ) ); $wp_user_query = new WP_User_Query( array( ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘first_name’, ‘value’ => $search_string, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘last_name’, ‘value’ => $search_string, ‘compare’ => ‘LIKE’ ) ) ) ); With a custom loop: <?php … Read more

Assigning a meta_query value based on regexp to wp_query fails

Meta query should be an array of arrays (every array contains one condition). So instead of $meta_query = array( ‘key’ => ‘offer’, ‘value’ => $off, ‘compare’ => ‘=’ ); $query->set( ‘meta_query’, $meta_query ); There should be $meta_query = array( array( ‘key’ => ‘offer’, ‘value’ => $off, ‘compare’ => ‘=’ ) ); $query->set( ‘meta_query’, $meta_query ); … Read more

Transliterating search term in another language

If you have PHP’s Intl extension installed, you can use the wonderful Transliterator class. I get some pretty good results, like this: $t = Transliterator::create(‘Latin-Greek’, Transliterator::FORWARD ); var_dump( [ ‘alfa’ => $t->transliterate(‘alfa’), ‘alpha’ => $t->transliterate(‘alpha’), ] ); Both these greeklish forms give me “άλφα”. I don’t know how it knows where to put the accent, … Read more

Setting custom search engine indexing for a “dynamic WordPress page” with htaccess

You’ll need the Header set …. directive, but to set it conditionally based on the URL. One way of doing this is to use mod_rewrite to set an environment variable (eg. ROBOTS_INDEX) when your URL criteria are met (for the URLs you want indexed) and use the env= argument to the Header directive to conditionally … Read more

Get PDF in media by ID

Don’t know why, but doing this worked… In my search.php, no problem. In content-search.php, no result. while (have_posts()) : the_post(); $attachment = wp_get_attachment_url(get_the_ID()); set_query_var(‘document’, $attachment); get_template_part(‘template-parts/content’, ‘search’); endwhile; EDIT As mention @Dave Romsey, do add_action( ‘pre_get_posts’, ‘attachment_search’ ); instead of add_filter( ‘pre_get_posts’, ‘attachment_search’ );

How to loop for every result found in the_content() when using the search query?

got a solution with https://stackoverflow.com/questions/15737408/php-find-all-occurrences-of-a-substring-in-a-string $lastPos = 0; $positions = array(); if($pos==”){} else{ while (($lastPos = strpos($content, $findme, $lastPos))!== false){ $positions[] = $lastPos; $lastPos = $lastPos + strlen($findme); } // Displays foreach ($positions as $eachPos){ $pos = $eachPos; $exctractAfterQuery = substr($content,($pos+strlen($findme) ),40); $exctractBeforeQuery = substr($content,$pos-40,40); $newContent .= “[…”.$exctractBeforeQuery.'<strong class=”search-highlight”>’.$findme.”</strong>”.$exctractAfterQuery.”…]<br>”; } } It works well and … Read more

Admin search not working for any type of post

you can try writing something that appends to your query var when the search is initiated something as such as: function gt_search_filter($query) { global $wp_query; if ($query->is_search) if($_REQUEST[‘s’]){ $wp_query->query_vars[‘s’] = $_REQUEST[‘s’]; } return $query; } add_filter(‘pre_get_posts’,’gt_search_filter’); this worked for me but remember this is quite insecure and not advised what other thing you can do … Read more