Hello,
I am having a strange issue on a site I was asked to look at. There was a search created several years ago for a custom post type and for whatever reason, it will not return search results for searches more than 5 characters long.
For example: searching Healt will return results with health in the name, but Health will return nothing.
Searching Partn will return results with partner, but if you search for partne or partner, the search returns nothing.
I am at a complete loss, and the AJAX search doesn’t seem to show anything about limiting the characters:
<?php
add_action(‘wp_ajax_the_agreements’, ‘the_agreements’);
add_action(‘wp_ajax_nopriv_the_agreements’, ‘the_agreements’);
function the_agreements( $params = array() ) {
global $post;
$per_page = 8;
$_GET[‘paged’] = ($_GET[‘paged’]) ? $_GET[‘paged’] : 1;
$args = array(
‘posts_per_page’ => $per_page,
‘post_type’ => ‘agreements’,
‘paged’ => $_GET[‘paged’],
#’order’ => ‘ASC’,
‘suppress_filters’ => false,
‘cache_results’ => false,
‘update_post_meta_cache’ => false,
‘update_post_term_cache’ => false
);
if ( $_GET[‘s’] ) {
$args[‘s’] = $_GET[‘s’];
} elseif ( $_GET[‘search’] ) {
$args[‘s’] = $_GET[‘search’];
} elseif ( $params[‘find’] ) {
define( ‘DO_SEARCH’, true );
$args[‘s’] = $params[‘find’];
}
$posts = get_posts( $args );
$args[‘posts_per_page’] = -1;
$args[‘fields’] = ‘ids’;
$total = count( get_posts( $args ) );
$pages = ceil( $total / $per_page );
$data = ‘ data-pages=”‘ . $pages . ‘” data-total=”‘ . $total . ‘”‘;
if ( $args[‘s’] ) {
$parser = array();
$parser[] = count( get_posts( $args ) );
$parser[] = ‘”‘ . $args[‘s’] . ‘”‘;
$filters[‘data-reset=”paged,search”‘] = vsprintf(_n(‘Found %d result for %s.’, ‘Found %d results for %s.’, $total, ‘rosetta’), $parser);
}
if ($_GET[‘paged’] && $_GET[‘paged’] != 1) {
$filters[‘data-reset=”paged”‘] = sprintf(__(‘Viewing page %d of %d.’, ‘rosetta’), $_GET[‘paged’], $pages );
}
grid_filters($filters);
?>
<div class=”paginated-items total-count”<?php echo $data; ?>>
<?php
if ( $posts ) {
foreach ( $posts as $item ) {
$doc = get_post_meta($item->ID, ‘_doc’, true);
$linkage_url = wp_get_attachment_url($doc);
$target = ‘ target=”_blank”‘;
?>
<div class=”paginated-item agreement-item”>
<?php /*<span class=”tag button fill”>Agreements</span>*/ ?>
<div class=”agreement-item-content”>
<span class=”title”><?php echo $item->post_title; ?></span>
<time datetime=”<?php echo get_the_date( ‘c’, $item ); ?>”>Posted: <?php echo get_the_date( ‘F j, Y’, $item ); ?></time>
</div><!– .content –>
<a href=”<?= $linkage_url ?>” class=”button fill with-arrow”<?= $target ?>>View</a>
</div><!– .paginated-item –>
<?php
}
} else {
?>
<div class=”paginated-item agreement-item”>
<h4 class=”no-results”><?php _e(‘Sorry, no results could be found.’, ‘rosetta’); ?></h4>
</div><!– .paginated-item –>
<?php
} #endif;
?>
</div><!– .paginated-items –>
<?php
define( ‘DO_SEARCH’, false );
if ( defined(‘DOING_AJAX’) && DOING_AJAX ) {
exit;
}
}
?>
If anyone has encountered this problem before, do you remember what you needed to change? Or maybe you know a function I should look for?
[ad_2]