WordPress search results

Completado Publicado hace 6 años Pagado a la entrega
Completado Pagado a la entrega

I need four custom codes for the [login to view URL] files of four different wordpress sites.

The purpose is to limit the wordpress search results.

site 1) Search only at the beginning of the title (of post/page)

site 2) Search only at the end of the title (of post/page)

site 3) Search only within the title, i.e. excluding the first and last letter of the title (of post/page)

site 4) Search anywhere in the title (of post/page) considering the asterisks as unknown letters (for example, if I search for h*ll*, I will find hello)

I already have the following code in [login to view URL] to limit search to post/page titles only and exactly. It works fine.

function ni_search_by_title_only( $search, &$wp_query )

{

global $wpdb;

if ( empty( $search ) )

return $search; // skip processing - no search term in query

$q = $wp_query->query_vars;

$n = ! empty( $q['exact'] ) ? '' : '%';

$search =

$searchand = '';

foreach ( (array) $q['search_terms'] as $term ) {

$term = esc_sql( like_escape( $term ) );

$search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";

$searchand = ' AND ';

}

if ( ! empty( $search ) ) {

$search = " AND ({$search}) ";

if ( ! is_user_logged_in() )

$search .= " AND ($wpdb->posts.post_password = '') ";

}

return $search;

}

add_filter( 'posts_search', 'ni_search_by_title_only', 500, 2 );

add_action('pre_get_posts', 'my_make_search_exact', 10);

function my_make_search_exact($query){

if(!is_admin() && $query->is_main_query() && $query->is_search) :

$query->set('exact', true);

endif;

}

PHP

Nº del proyecto: #15460194

Sobre el proyecto

4 propuestas Proyecto remoto Activo hace 6 años

Adjudicado a:

€20 EUR en 1 día
(125 comentarios)
6.8

4 freelancers están ofertando un promedio de €23 por este trabajo

olasheni

Hey, I'm interested in your project. Please send me a message so that we can discuss more. Relevant Skills and Experience HTML CSS JavaScript PHP jQuery/AJAX SQL Laravel WordPress API Integration Shopify Integration W Más

€23 EUR en 1 día
(44 comentarios)
4.9
notansolutions

A proposal has not yet been provided

€26 EUR en 15 días
(0 comentarios)
0.0