tag para name loop first filtro fields docs custom con buscador all advanced acf php wordpress advanced-custom-fields

php - para - Agregue campos ACF a la página de resultados de búsqueda WordPress



loop advanced custom fields (1)

También puede hacerlo utilizando el complemento, pero use el código siguiente para evitar el complemento.

Necesita agregar este código en su archivo function.php

<?php /** * [list_searcheable_acf list all the custom fields we want to include in our search query] * @return [array] [list of custom fields] */ function list_searcheable_acf(){ $list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF"); return $list_searcheable_acf; } /** * [advanced_custom_search search that encompasses ACF/advanced custom fields and taxonomies and split expression before request] * @param [query-part/string] $where [the initial "where" part of the search query] * @param [object] $wp_query [] * @return [query-part/string] $where [the "where" part of the search query as we customized] * see https://vzurczak.wordpress.com/2013/06/15/extend-the-default-wordpress-search/ * credits to Vincent Zurczak for the base query structure/spliting tags section */ function advanced_custom_search( $where, &$wp_query ) { global $wpdb; if ( empty( $where )) return $where; // get search expression $terms = $wp_query->query_vars[ ''s'' ]; // explode search expression to get search terms $exploded = explode( '' '', $terms ); if( $exploded === FALSE || count( $exploded ) == 0 ) $exploded = array( 0 => $terms ); // reset search in order to rebuilt it as we whish $where = ''''; // get searcheable_acf, a list of advanced custom fields you want to search content in $list_searcheable_acf = list_searcheable_acf(); foreach( $exploded as $tag ) : $where .= " AND ( (wp_posts.post_title LIKE ''%$tag%'') OR (wp_posts.post_content LIKE ''%$tag%'') OR EXISTS ( SELECT * FROM wp_postmeta WHERE post_id = wp_posts.ID AND ("; foreach ($list_searcheable_acf as $searcheable_acf) : if ($searcheable_acf == $list_searcheable_acf[0]): $where .= " (meta_key LIKE ''%" . $searcheable_acf . "%'' AND meta_value LIKE ''%$tag%'') "; else : $where .= " OR (meta_key LIKE ''%" . $searcheable_acf . "%'' AND meta_value LIKE ''%$tag%'') "; endif; endforeach; $where .= ") ) OR EXISTS ( SELECT * FROM wp_comments WHERE comment_post_ID = wp_posts.ID AND comment_content LIKE ''%$tag%'' ) OR EXISTS ( SELECT * FROM wp_terms INNER JOIN wp_term_taxonomy ON wp_term_taxonomy.term_id = wp_terms.term_id INNER JOIN wp_term_relationships ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id WHERE ( taxonomy = ''post_tag'' OR taxonomy = ''category'' OR taxonomy = ''myCustomTax'' ) AND object_id = wp_posts.ID AND wp_terms.name LIKE ''%$tag%'' ) )"; endforeach; return $where; } add_filter( ''posts_search'', ''advanced_custom_search'', 500, 2 );

para referencia - https://gist.github.com/charleslouis/5924863

Pruebe esta solución si la primera no funciona.

https://support.advancedcustomfields.com/forums/topic/making-customfields-searchable/

Tengo un archivo llamado search.php, donde se agregan todos los resultados de la búsqueda. El formulario de búsqueda se encuentra en la página de inicio. El problema es que no tengo una página especial para los resultados de búsqueda, pero quiero agregar campos ACF a esta página. He buscado en el menú desplegable ''ubicación'' en el complemento ACF, pero no puedo encontrar el archivo search.php para agregar grupos. Lo siento si mi explicación es un poco vaga, pero no sé cómo explicar esto exactamente.

Resumen, quiero agregar campos de ACF a mi página de resultados de búsqueda search.php.

Terminología: ACF representa el complemento Advanced Custom Fields en WordPress.