Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Dummy/Empty Item generated in results
- This topic has 9 replies, 2 voices, and was last updated 10 months ago by
Ernest Marcinko.
-
AuthorPosts
-
August 1, 2025 at 1:25 pm #55110
dilinanand_Nsv5
ParticipantHi,
When I do a search using any user name. The results page shows a dummy/empty item at first position. There’s a dummy file image in place of thumbnail and no post title or post description is there. I have attached the screenshot. Below is the html output of the item
<div class=”tdb_module_loop td_module_wrap td-animation-stack td-meta-info-hide td-cpt-“>
<div class=”td-module-container td-category-pos-image”>
<div class=”td-image-container”>
<div class=”td-module-thumb”>edit<span class=”entry-thumb td-thumb-css ” style=”background-image: url(https://www.electronicsforu.com/wp-content/plugins/td-composer/legacy/Newspaper/assets/images/no-thumb/td_696x0.png)”></span></div>
</div>
<div class=”td-module-meta-info”>
<h3 class=”entry-title td-module-title”></h3>
<div class=”td-editor-date”>
<span class=”td-author-date”></span>
</div>
<div class=”td-excerpt”></div>
</div>
</div>
</div>August 1, 2025 at 2:14 pm #55116Ernest Marcinko
KeymasterHi,
I suspect it might be a taxonomy term or a user type result that is not possible to display on the results page.
Can you please check if it disappears if you disable search for users here: https://i.imgur.com/gfFJheu.png
August 1, 2025 at 2:29 pm #55117dilinanand_Nsv5
ParticipantYes, when I disable the option the item gets removed. But I want the user search.
August 1, 2025 at 2:45 pm #55120Ernest Marcinko
KeymasterOkay, I think it’s doable with a small custom code snippet.
Use this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
add_filter( 'asp_query_args', function ( $args ) { if ( !$args['_ajax_search'] ) { $args['search_type'] = array('cpt'); } return $args; } );If you need help with it just let me know.
August 1, 2025 at 2:59 pm #55121dilinanand_Nsv5
ParticipantWhile adding this code, should I enable the user search option?
Also this code will not conflict with other code of asp? I have below codes added currently// Hook into Ajax Search Pro’s form rendering to inject a hidden input with the category ID
add_action(‘asp_layout_in_form’, ‘asp_layout_in_form_archive_input’, 10, 1);
function asp_layout_in_form_archive_input($search_id) {// Only apply to these instance IDs
$allowed_ids = array(11, 12); // update these as needed
if (!in_array($search_id, $allowed_ids)) return;global $wp, $post;
$term = null;// 1. On a category archive page (handles nested child categories too)
if (!empty($wp->query_vars[‘category_name’])) {
$category_path = $wp->query_vars[‘category_name’];
$slugs = explode(‘/’, $category_path); // For nested categories
$last_slug = end($slugs); // Use the final slug$term = get_term_by(‘slug’, $last_slug, ‘category’);
}// 2. On search results page, get category from URL parameter
if (isset($_GET[‘asp_tax_archive’])) {
$term_id = intval($_GET[‘asp_tax_archive’]);
$term = get_term($term_id, ‘category’);
}// Output hidden input field if valid term is found
if (!empty($term) && !is_wp_error($term)) {
echo ‘<input type=”hidden” name=”asp_tax_archive” value=”‘ . esc_attr($term->term_id) . ‘” data-asp-hidden-field>’;
}
}// Modify the Ajax Search Pro query arguments to restrict search results to a specific taxonomy term (e.g., category)
add_filter(‘asp_query_args’, ‘asp_archive_page_category_restriction’, 10, 2);
function asp_archive_page_category_restriction($args,$search_id) {// Only apply to these instance IDs
$allowed_ids = array(11, 12);
if (!in_array($search_id, $allowed_ids)) return $args;$archive_term_id = null;
// Case 1: If the search options are submitted via POST, extract the hidden category ID
if (isset($_POST[‘options’])) {
parse_str($_POST[‘options’], $so);if (!empty($so[‘asp_tax_archive’])) {
$archive_term_id = $so[‘asp_tax_archive’];
}
}// Case 2: If the search was triggered via a GET request, fetch the category ID from the URL
elseif (!empty($_GET[‘asp_tax_archive’])) {
$archive_term_id = $_GET[‘asp_tax_archive’];
}// If a valid taxonomy term ID is present, modify the search query to filter by that term
if ($archive_term_id) {
$term = get_term($archive_term_id);if (!is_wp_error($term)) {
$args[‘post_tax_filter’][] = array(
‘taxonomy’ => $term->taxonomy, // e.g., ‘category’
‘include’ => array($term->term_id), // Term ID to include
‘exclude’ => array(), // No exclusions
‘logic’ => ‘AND’, // Combine filters using AND logic
‘allow_empty’ => false // Do not allow empty result sets
);
}
}return $args;
}August 1, 2025 at 3:01 pm #55122Ernest Marcinko
KeymasterYes, you should enable the user search option, I forgot to mention.
No, it will not conflict with the other code, you can safely add it.
August 1, 2025 at 3:11 pm #55124dilinanand_Nsv5
ParticipantGreat, it is working. The items are removed.
Also I want to know can I have users as result items on results page?
August 1, 2025 at 3:16 pm #55126Ernest Marcinko
KeymasterWell wordpress in general does not allow anything else than posts and other post types as results.
The search tries to “trick” wordpress by pushing a fake post instead of the users, and then correcting the titles and the URLs later – but unfortunately in many cases it won’t work, as it’s not supposed to work in the first place.
The only way to maybe have those results is by editing the search results template file in the theme directory and integrating the ajax search pro theme functions to get the original result titles, images, excerpts and urls. It is still possible that these won’t work, strongly depends if the query persists the data sent by the search.
August 1, 2025 at 4:07 pm #55131dilinanand_Nsv5
ParticipantOkay.
Thanks for your help and quick response.
August 1, 2025 at 4:07 pm #55132Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- You must be logged in to reply to this topic.