Utilizzo della meta query ('meta_query') con una query di ricerca ('s')
-
-
Quello che vuoifarenon èpossibile utilizzando una sola query di ricerca.Dovrestieseguireentrambe le query separatamentee quindi unirleinsieme.Questo è stato descrittoin quest'altra risposta.Dovrebbe darti unamano su comefarlo.http://wordpress.stackexchange.com/questions/55519/can-i-merge-2-new-wp-queryvariable-sWhat you are wanting to do isn't possible using just one search query. You would need to run both queries separately and then merge them together. This has been described at this other answer. It should give you a hand with how to do it. http://wordpress.stackexchange.com/questions/55519/can-i-merge-2-new-wp-queryvariable-s
- 0
- 2013-01-08
- Nick Perkins
-
11 risposta
- voti
-
- 2013-01-08
Secondoil suggerimento di Nick Perkins ,ho dovuto unire due queryin questomodo:
$q1 = get_posts(array( 'fields' => 'ids', 'post_type' => 'post', 's' => $query )); $q2 = get_posts(array( 'fields' => 'ids', 'post_type' => 'post', 'meta_query' => array( array( 'key' => 'speel', 'value' => $query, 'compare' => 'LIKE' ) ) )); $unique = array_unique( array_merge( $q1, $q2 ) ); $posts = get_posts(array( 'post_type' => 'posts', 'post__in' => $unique, 'post_status' => 'publish', 'posts_per_page' => -1 )); if( $posts ) : foreach( $posts as $post ) : setup_postdata($post); // now use standard loop functions like the_title() etc. enforeach; endif;
As per Nick Perkins' suggestion, I had to merge two queries like so:
$q1 = get_posts(array( 'fields' => 'ids', 'post_type' => 'post', 's' => $query )); $q2 = get_posts(array( 'fields' => 'ids', 'post_type' => 'post', 'meta_query' => array( array( 'key' => 'speel', 'value' => $query, 'compare' => 'LIKE' ) ) )); $unique = array_unique( array_merge( $q1, $q2 ) ); $posts = get_posts(array( 'post_type' => 'posts', 'post__in' => $unique, 'post_status' => 'publish', 'posts_per_page' => -1 )); if( $posts ) : foreach( $posts as $post ) : setup_postdata($post); // now use standard loop functions like the_title() etc. enforeach; endif;
-
Questonon è ancorapossibile senza unafusionenel 2016?Stomodificando la query di ricercatramitepre_get_posts,quindi questanon è davvero un'opzione ...Is this still not possible without merging in 2016? I'm editing search query via pre_get_posts, so this is really not an option ...
- 1
- 2016-02-09
- trainoasis
-
@trainoasis Non credo.Loprovo dalle ultime 2 oree una ricerca su Googlemi haportato qui.@trainoasis I don't think so. I have been trying it since last 2 hours and a google search got me here.
- 0
- 2016-11-05
- Umair Khan Jadoon
-
- 2015-11-17
Ho cercatoper ore una soluzione a questoproblema. L'unione di arraynon è la strada dapercorrere,soprattutto quando le query sono complessee deviesserein grado di aggiungerle allemeta queryin futuro. La soluzione semplicisticamentebella è cambiare "s" a uno che consente sia la ricerca dititoli che dimeta campi.
add_action( 'pre_get_posts', function( $q ) { if( $title = $q->get( '_meta_or_title' ) ) { add_filter( 'get_meta_sql', function( $sql ) use ( $title ) { global $wpdb; // Only run once: static $nr = 0; if( 0 != $nr++ ) return $sql; // Modified WHERE $sql['where'] = sprintf( " AND ( %s OR %s ) ", $wpdb->prepare( "{$wpdb->posts}.post_title like '%%%s%%'", $title), mb_substr( $sql['where'], 5, mb_strlen( $sql['where'] ) ) ); return $sql; }); } });
Utilizzo:
$meta_query = array(); $args = array(); $search_string = "test"; $meta_query[] = array( 'key' => 'staff_name', 'value' => $search_string, 'compare' => 'LIKE' ); $meta_query[] = array( 'key' => 'staff_email', 'value' => $search_string, 'compare' => 'LIKE' ); //if there is more than one meta query 'or' them if(count($meta_query) > 1) { $meta_query['relation'] = 'OR'; } // The Query $args['post_type'] = "staff"; $args['_meta_or_title'] = $search_string; //not using 's' anymore $args['meta_query'] = $meta_query; $the_query = new WP_Query($args)
I have been searching for hours for a solution to this problem. Array merging is not the way to go, especially when the queries are complex and you must be able to add to meta queries in the future. The solution which is simplistically beautiful is to change 's' to one which allows both searching titles and meta fields.
add_action( 'pre_get_posts', function( $q ) { if( $title = $q->get( '_meta_or_title' ) ) { add_filter( 'get_meta_sql', function( $sql ) use ( $title ) { global $wpdb; // Only run once: static $nr = 0; if( 0 != $nr++ ) return $sql; // Modified WHERE $sql['where'] = sprintf( " AND ( %s OR %s ) ", $wpdb->prepare( "{$wpdb->posts}.post_title like '%%%s%%'", $title), mb_substr( $sql['where'], 5, mb_strlen( $sql['where'] ) ) ); return $sql; }); } });
Usage:
$meta_query = array(); $args = array(); $search_string = "test"; $meta_query[] = array( 'key' => 'staff_name', 'value' => $search_string, 'compare' => 'LIKE' ); $meta_query[] = array( 'key' => 'staff_email', 'value' => $search_string, 'compare' => 'LIKE' ); //if there is more than one meta query 'or' them if(count($meta_query) > 1) { $meta_query['relation'] = 'OR'; } // The Query $args['post_type'] = "staff"; $args['_meta_or_title'] = $search_string; //not using 's' anymore $args['meta_query'] = $meta_query; $the_query = new WP_Query($args)
-
questo èilmodogiusto,this is the right way,
- 0
- 2016-08-12
- Zorox
-
Fantastico,questo hafunzionatomoltobene perme.Ottima soluzione!Grazie!Fantastic, this worked very well for me. Great solution! Thanks!
- 0
- 2017-09-23
- Fabiano
-
Questa è una query,non una ricerca.Se haiplugin chefunzionano sulla ricerca,nonfunziona.Ho sbagliato?This is a query, not a search. If you have plugins that work on search, it doesn't work. Am I wrong?
- 0
- 2017-10-30
- marek.m
-
@marek.m avrestibisogno dipersonalizzareilplugin (magari usando unfiltro se disponibile)per aggiungere lameta query.@marek.m you would need to customize the plugin (perhaps using a filter if its available) to add the meta query.
- 1
- 2020-01-21
- FooBar
-
- 2014-03-04
Èpossibile ridurremolto codice utilizzando una versionemodificata di questa risposta .
$q1 = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1, 's' => $query )); $q2 = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'speel', 'value' => $query, 'compare' => 'LIKE' ) ) )); $result = new WP_Query(); $result->posts = array_unique( array_merge( $q1->posts, $q2->posts ), SORT_REGULAR ); $result->post_count = count( $result->posts );
A lot of code can be reduced by using a modified version of this answer.
$q1 = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1, 's' => $query )); $q2 = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'speel', 'value' => $query, 'compare' => 'LIKE' ) ) )); $result = new WP_Query(); $result->posts = array_unique( array_merge( $q1->posts, $q2->posts ), SORT_REGULAR ); $result->post_count = count( $result->posts );
-
Questo hafunzionato allagrandeperme (soprattuttoperché avevobisogno di usare WP_Queryinvece diget_posts).Ho dovutomodificare latua rigapost_countin modo chefosse: `` $ result->post_count=count ($ result->posts); `` ``perché altrimenti stavo ottenendo solo 1 risultato.This worked great for me (especially since I needed to use WP_Query instead of get_posts). I did have to modify your post_count line to be: ```$result->post_count = count( $result->posts );``` because I was only getting 1 result otherwise.
- 0
- 2015-05-27
- GreatBlakes
-
- 2016-08-22
ho avuto lo stessoproblema,perilmionuovo sito ho appena aggiunto unnuovometa & quot;titolo & quot;:
functions.php
add_action('save_post', 'title_to_meta'); function title_to_meta($post_id) { update_post_meta($post_id, 'title', get_the_title($post_id)); }
Epoi .. aggiungi semplicemente qualcosa delgenere:
$sub = array('relation' => 'OR'); $sub[] = array( 'key' => 'tags', 'value' => $_POST['q'], 'compare' => 'LIKE', ); $sub[] = array( 'key' => 'description', 'value' => $_POST['q'], 'compare' => 'LIKE', ); $sub[] = array( 'key' => 'title', 'value' => $_POST['q'], 'compare' => 'LIKE', ); $params['meta_query'] = $sub;
Cosane pensi di questa soluzione alternativa?
i had the same problem, for my new site i just added a new meta "title" :
functions.php
add_action('save_post', 'title_to_meta'); function title_to_meta($post_id) { update_post_meta($post_id, 'title', get_the_title($post_id)); }
And then.. just add something like that :
$sub = array('relation' => 'OR'); $sub[] = array( 'key' => 'tags', 'value' => $_POST['q'], 'compare' => 'LIKE', ); $sub[] = array( 'key' => 'description', 'value' => $_POST['q'], 'compare' => 'LIKE', ); $sub[] = array( 'key' => 'title', 'value' => $_POST['q'], 'compare' => 'LIKE', ); $params['meta_query'] = $sub;
What do you think about this workaround ?
-
In realtànon èmale,ma richiede di salvarenuovamentetuttii postesistenti o diiniziare a usarliprima diiniziare ad aggiungere contenuti.That's actually not bad, but requires you to either re-save all existing posts or start using it before you start adding content.
- 1
- 2016-12-06
- Berend
-
@Berendpotrestiprobabilmente scrivere unafunzione che ottienetuttii poste li ripete aggiornandopost_metaper ciascuno.Includiloin unmodello ofunzionepersonalizzato,eseguilo una volta,quindieliminalo.@Berend you could probably write a function that gets all posts and loops through them updating the post_meta for each. Include it in a custom template or function, run it once, then discard it.
- 0
- 2018-05-23
- Slam
-
- 2016-10-12
Ho ottimizzato unpo 'la risposta di @Stabir Kira
function wp78649_extend_search( $query ) { $search_term = filter_input( INPUT_GET, 's', FILTER_SANITIZE_NUMBER_INT) ?: 0; if ( $query->is_search && !is_admin() && $query->is_main_query() && //your extra condition ) { $query->set('meta_query', [ [ 'key' => 'meta_key', 'value' => $search_term, 'compare' => '=' ] ]); add_filter( 'get_meta_sql', function( $sql ) { global $wpdb; static $nr = 0; if( 0 != $nr++ ) return $sql; $sql['where'] = mb_eregi_replace( '^ AND', ' OR', $sql['where']); return $sql; }); } return $query; } add_action( 'pre_get_posts', 'wp78649_extend_search');
Orapuoi cercareper (titolo,contenuto,estratto) o (meta campo) o (entrambi).
I have optimized @Stabir Kira answer a bit
function wp78649_extend_search( $query ) { $search_term = filter_input( INPUT_GET, 's', FILTER_SANITIZE_NUMBER_INT) ?: 0; if ( $query->is_search && !is_admin() && $query->is_main_query() && //your extra condition ) { $query->set('meta_query', [ [ 'key' => 'meta_key', 'value' => $search_term, 'compare' => '=' ] ]); add_filter( 'get_meta_sql', function( $sql ) { global $wpdb; static $nr = 0; if( 0 != $nr++ ) return $sql; $sql['where'] = mb_eregi_replace( '^ AND', ' OR', $sql['where']); return $sql; }); } return $query; } add_action( 'pre_get_posts', 'wp78649_extend_search');
Now you can search by (title, content, excrept) or (meta field) or (both of them).
-
- 2013-01-08
Beh,è una specie di hackmafunziona. Devi aggiungereilfiltroposts_clauses. Questafunzione difiltro verifica lapresenza di una qualsiasi delleparole della querynel campopersonalizzato "speel"e la query rimanente rimaneintatta.
function custom_search_where($pieces) { // filter for your query if (is_search() && !is_admin()) { global $wpdb; $keywords = explode(' ', get_query_var('s')); $query = ""; foreach ($keywords as $word) { // skip possible adverbs and numbers if (is_numeric($word) || strlen($word) <= 2) continue; $query .= "((mypm1.meta_key = 'speel')"; $query .= " AND (mypm1.meta_value LIKE '%{$word}%')) OR "; } if (!empty($query)) { // add to where clause $pieces['where'] = str_replace("(((wp_posts.post_title LIKE '%", "( {$query} ((wp_posts.post_title LIKE '%", $pieces['where']); $pieces['join'] = $pieces['join'] . " INNER JOIN {$wpdb->postmeta} AS mypm1 ON ({$wpdb->posts}.ID = mypm1.post_id)"; } } return ($pieces); } add_filter('posts_clauses', 'custom_search_where', 20, 1);
Well its kind of a hack but it works. You need to add posts_clauses filter. This filter function check for the any of the query word exists in the custom field "speel" and the remaining query stays intact.
function custom_search_where($pieces) { // filter for your query if (is_search() && !is_admin()) { global $wpdb; $keywords = explode(' ', get_query_var('s')); $query = ""; foreach ($keywords as $word) { // skip possible adverbs and numbers if (is_numeric($word) || strlen($word) <= 2) continue; $query .= "((mypm1.meta_key = 'speel')"; $query .= " AND (mypm1.meta_value LIKE '%{$word}%')) OR "; } if (!empty($query)) { // add to where clause $pieces['where'] = str_replace("(((wp_posts.post_title LIKE '%", "( {$query} ((wp_posts.post_title LIKE '%", $pieces['where']); $pieces['join'] = $pieces['join'] . " INNER JOIN {$wpdb->postmeta} AS mypm1 ON ({$wpdb->posts}.ID = mypm1.post_id)"; } } return ($pieces); } add_filter('posts_clauses', 'custom_search_where', 20, 1);
-
- 2018-05-30
Tutte le soluzioniprecedenti restituiscono risultati solo seesiste una corrispondenzanellameta chiave speel.Se hai risultati altrovemanonin questo camponon otterrainulla.Nessuno lo vuole.
Ènecessario unjoin sinistro.Quanto seguene creerà uno.
$meta_query_args = array( 'relation' => 'OR', array( 'key' => 'speel', 'value' => $search_term, 'compare' => 'LIKE', ), array( 'key' => 'speel', 'compare' => 'NOT EXISTS', ), ); $query->set('meta_query', $meta_query_args);
All of the above solutions only return results if a match exists in the speel meta key. If you have results elsewhere but not in this field you'll get nothing. Nobody wants that.
A left join is needed. The following will create one.
$meta_query_args = array( 'relation' => 'OR', array( 'key' => 'speel', 'value' => $search_term, 'compare' => 'LIKE', ), array( 'key' => 'speel', 'compare' => 'NOT EXISTS', ), ); $query->set('meta_query', $meta_query_args);
-
- 2020-03-19
perme funzionaperfettamenteil codice successivo:
$search_word = $_GET['id']; $data['words'] = trim(urldecode($search_word)); $q1 = new WP_Query( array( 'post_type' => array('notas', 'productos'), 'posts_per_page' => -1, 's' => $search_word )); $q2 = new WP_Query( array( 'post_type' => array('notas', 'productos'), 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'subtitulo', 'value' => $search_word, 'compare' => 'LIKE' ), array( 'key' => 'thumbnail_bajada', 'value' => $search_word, 'compare' => 'LIKE' ) ) )); $result = new WP_Query(); $result->posts = array_unique( array_merge( $q1->posts, $q2->posts ), SORT_REGULAR ); $result->post_count = count( $result->posts );
for me works perfect the next code:
$search_word = $_GET['id']; $data['words'] = trim(urldecode($search_word)); $q1 = new WP_Query( array( 'post_type' => array('notas', 'productos'), 'posts_per_page' => -1, 's' => $search_word )); $q2 = new WP_Query( array( 'post_type' => array('notas', 'productos'), 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'subtitulo', 'value' => $search_word, 'compare' => 'LIKE' ), array( 'key' => 'thumbnail_bajada', 'value' => $search_word, 'compare' => 'LIKE' ) ) )); $result = new WP_Query(); $result->posts = array_unique( array_merge( $q1->posts, $q2->posts ), SORT_REGULAR ); $result->post_count = count( $result->posts );
-
- 2018-12-11
Questa è un'ottima soluzione,ma devi risolvere una cosa. Quando chiami "post__in" deviimpostare un array di IDe $ unique è un array dipost.
esempio:
$q1 = get_posts(array( 'fields' => 'ids', 'post_type' => 'post', 's' => $query )); $q2 = get_posts(array( 'fields' => 'ids', 'post_type' => 'post', 'meta_query' => array( array( 'key' => 'speel', 'value' => $query, 'compare' => 'LIKE' ) ) )); $unique = array_unique( array_merge( $q1->posts, $q2->posts ) ); $array = array(); //here you initialize your array foreach($posts as $post) { $array[] = $post->ID; //fill the array with post ID } $posts = get_posts(array( 'post_type' => 'posts', 'post__in' => $array, 'post_status' => 'publish', 'posts_per_page' => -1 ));
This is a great solution but you need to fix one thing. When you call 'post__in' you need to set an array of ids and $unique is an array of posts.
example:
$q1 = get_posts(array( 'fields' => 'ids', 'post_type' => 'post', 's' => $query )); $q2 = get_posts(array( 'fields' => 'ids', 'post_type' => 'post', 'meta_query' => array( array( 'key' => 'speel', 'value' => $query, 'compare' => 'LIKE' ) ) )); $unique = array_unique( array_merge( $q1->posts, $q2->posts ) ); $array = array(); //here you initialize your array foreach($posts as $post) { $array[] = $post->ID; //fill the array with post ID } $posts = get_posts(array( 'post_type' => 'posts', 'post__in' => $array, 'post_status' => 'publish', 'posts_per_page' => -1 ));
-
- 2019-01-16
La risposta di @ satbir-kirafunzionabenissimoma cercherà solonelmetae neltitolo delpost. Se vuoi che cerchimeta,titoloe contenuto,ecco la versionemodificata.
add_action( 'pre_get_posts', function( $q ) { if( $title = $q->get( '_meta_or_title' ) ) { add_filter( 'get_meta_sql', function( $sql ) use ( $title ) { global $wpdb; // Only run once: static $nr = 0; if( 0 != $nr++ ) return $sql; // Modified WHERE $sql['where'] = sprintf( " AND ( (%s OR %s) OR %s ) ", $wpdb->prepare( "{$wpdb->posts}.post_title like '%%%s%%'", $title), $wpdb->prepare( "{$wpdb->posts}.post_content like '%%%s%%'", $title), mb_substr( $sql['where'], 5, mb_strlen( $sql['where'] ) ) ); return $sql; }); } });
Edeccoil suo utilizzo:
$args['_meta_or_title'] = $get['search']; //not using 's' anymore $args['meta_query'] = array( 'relation' => 'OR', array( 'key' => '_ltc_org_name', 'value' => $get['search'], 'compare' => 'LIKE' ), array( 'key' => '_ltc_org_school', 'value' => $get['search'], 'compare' => 'LIKE' ), array( 'key' => '_ltc_district_address', 'value' => $get['search'], 'compare' => 'LIKE' ) );
Sostituisci
$get['search']
coniltuo valore di ricerca@satbir-kira answer works great but it will only search through the meta and post title. If you want it to search through meta, title and content, here is the modified version.
add_action( 'pre_get_posts', function( $q ) { if( $title = $q->get( '_meta_or_title' ) ) { add_filter( 'get_meta_sql', function( $sql ) use ( $title ) { global $wpdb; // Only run once: static $nr = 0; if( 0 != $nr++ ) return $sql; // Modified WHERE $sql['where'] = sprintf( " AND ( (%s OR %s) OR %s ) ", $wpdb->prepare( "{$wpdb->posts}.post_title like '%%%s%%'", $title), $wpdb->prepare( "{$wpdb->posts}.post_content like '%%%s%%'", $title), mb_substr( $sql['where'], 5, mb_strlen( $sql['where'] ) ) ); return $sql; }); } });
And here is it's usage:
$args['_meta_or_title'] = $get['search']; //not using 's' anymore $args['meta_query'] = array( 'relation' => 'OR', array( 'key' => '_ltc_org_name', 'value' => $get['search'], 'compare' => 'LIKE' ), array( 'key' => '_ltc_org_school', 'value' => $get['search'], 'compare' => 'LIKE' ), array( 'key' => '_ltc_district_address', 'value' => $get['search'], 'compare' => 'LIKE' ) );
Replace
$get['search']
with your search value -
- 2020-02-19
Ecco un altromodo,bastamodificare la richiesta conilfiltro "posts_where_request". Tutto sarà ancora quellopredefinitotranne ('s' AND 'meta_query')=> ('s' OR 'meta_query').
AND ( ((posts.post_title LIKE 'Lily') OR (posts.post_excerpt LIKE 'Lily') OR (posts.post_content LIKE 'Lily')) ) AND ( ( postmeta.meta_key = 'author' AND postmeta.meta_value LIKE 'Lily' ) ) => AND ( ( ( postmeta.meta_key = 'author' AND postmeta.meta_value LIKE 'Lily' ) ) OR ((posts.post_title LIKE 'Lily') OR (posts.post_excerpt LIKE 'Lily') OR (posts.post_content LIKE 'Lily')) )
questo èil codice
function edit_request_wp_query( $where ) { global $wpdb; if ( strpos($where, $wpdb->postmeta.'.meta_key') && strpos($where, $wpdb->posts.'.post_title') ) { $string = $where; $index_meta = index_argument_in_request($string, $wpdb->postmeta.'.meta_key', $wpdb->postmeta.'.meta_value'); $meta_query = substr($string, $index_meta['start'], $index_meta['end']-$index_meta['start']); $string = str_replace( $meta_query, '', $string ); $meta_query = ltrim($meta_query, 'AND').' OR '; $index_s = index_argument_in_request($string, $wpdb->posts.'.post_title'); $insert_to = strpos($string, '(', $index_s['start'])+1; $string = substr_replace($string, $meta_query, $insert_to, 0); $where = $string; } return $where; } add_filter('posts_where_request', 'edit_request_wp_query'); function index_argument_in_request($string, $key_start, $key_end = '') { if (!$key_end) $key_end = $key_start; $index_key_start = strpos($string, $key_start); $string_before = substr($string, 0, $index_key_start); $index_start = strrpos($string_before, 'AND'); $last_index_key = strrpos($string, $key_end); $index_end = strpos($string, 'AND', $last_index_key); return ['start' => $index_start, 'end' => $index_end]; }
Here's another way, just change the request with the 'posts_where_request' filter. Everything will still be the default except ('s' AND 'meta_query') => ('s' OR 'meta_query').
AND ( ((posts.post_title LIKE 'Lily') OR (posts.post_excerpt LIKE 'Lily') OR (posts.post_content LIKE 'Lily')) ) AND ( ( postmeta.meta_key = 'author' AND postmeta.meta_value LIKE 'Lily' ) ) => AND ( ( ( postmeta.meta_key = 'author' AND postmeta.meta_value LIKE 'Lily' ) ) OR ((posts.post_title LIKE 'Lily') OR (posts.post_excerpt LIKE 'Lily') OR (posts.post_content LIKE 'Lily')) )
this is the code
function edit_request_wp_query( $where ) { global $wpdb; if ( strpos($where, $wpdb->postmeta.'.meta_key') && strpos($where, $wpdb->posts.'.post_title') ) { $string = $where; $index_meta = index_argument_in_request($string, $wpdb->postmeta.'.meta_key', $wpdb->postmeta.'.meta_value'); $meta_query = substr($string, $index_meta['start'], $index_meta['end']-$index_meta['start']); $string = str_replace( $meta_query, '', $string ); $meta_query = ltrim($meta_query, 'AND').' OR '; $index_s = index_argument_in_request($string, $wpdb->posts.'.post_title'); $insert_to = strpos($string, '(', $index_s['start'])+1; $string = substr_replace($string, $meta_query, $insert_to, 0); $where = $string; } return $where; } add_filter('posts_where_request', 'edit_request_wp_query'); function index_argument_in_request($string, $key_start, $key_end = '') { if (!$key_end) $key_end = $key_start; $index_key_start = strpos($string, $key_start); $string_before = substr($string, 0, $index_key_start); $index_start = strrpos($string_before, 'AND'); $last_index_key = strrpos($string, $key_end); $index_end = strpos($string, 'AND', $last_index_key); return ['start' => $index_start, 'end' => $index_end]; }
Tentativo di creare una ricerca che cerchinon solo leimpostazionipredefinite (titolo,contenutoecc.)ma anche un campopersonalizzato specifico.
Lamia domanda attuale:
Questo restituiscepost che corrispondono sia alla query di ricerca CHE allameta query,ma vorrei anche che restituisse anchepostin cui corrisponde semplicemente a una diesse.
Qualcheidea?