Search Result
-
Hello,
Can this plugin exclude search functionality on a specific page archive built by the Elementor builder?
I am using the search filter provided by Jet Engine to filter the listing posts of CPT Resource on this page: https://shabaka.bravefactor.com/analysis/. However, the filter shows results from all pages. Due to this issue, I would like to exclude the Relevanssi function from only this archive page.
i have try this code:
add_action( 'wp_head', function() { if ( is_post_type_archive( 'resources' ) ) { // Optionally limit this code to a specific page or template, with a Conditional Tag. // Disable Relevanssi entirely remove_filter( 'posts_request', 'relevanssi_prevent_default_request' ); remove_filter( 'posts_pre_query', 'relevanssi_query', 99 ); remove_filter( 'the_posts', 'relevanssi_query', 99 ); } } );
but still doesn’t work
-
This topic was modified 1 year, 2 months ago by
zeinz232.
The page I need help with: [log in to see the link]
-
This topic was modified 1 year, 2 months ago by
-
Yes, it’s possible to conditionally disable Relevanssi. The tool for this is the
relevanssi_search_ok
filter hook. See the documentation here.add_filter( 'relevanssi_prevent_default_request', 'rlv_ufaq_query', 10, 2 ); add_filter( 'relevanssi_search_ok', 'rlv_ufaq_query', 10, 2 ); function rlv_ufaq_query( $do_stuff, $query ) { if ( is_post_type_archive( 'resources' ) ) { $do_stuff = false; } return $do_stuff; }
and
add_filter( 'relevanssi_search_ok', function( $ok, $query ) { if ( is_post_type_archive( 'resources' ) ) { $ok = false; } return $ok; }, 10, 2 );
All of doesn’t work?
can you help meI can’t help much, because I have no idea what your site does and how the search works the way it does. Jet Engine is a black box for me, I don’t know what’s inside it.
In the
relevanssi_search_ok
function, you get the WP_Query object as the second parameter. Instead ofis_post_type_archive()
you can look at the search parameters in that $query variable to see if there’s something that can be used to identify the Jet Engine search.add_filter( 'relevanssi_search_ok', function( $ok, $query ) { error_log(print_r($query, true)); return $ok; }, 10, 2 );
What does this print to the server PHP error log when you do the search?
The
relevanssi_prevent_default_request
filter doesn’t seem necessary; if it worked in the first place, the search would come up empty.You can also try if the
relevanssi_search_ok
is a possible solution with this:add_filter( 'relevanssi_search_ok', function( $ok, $query ) { return false; }, 10, 2 );
If this helps, then it’s worth pursuing this solution. If this doesn’t help, then another solution is required.
this, the PHP error log.
[26-Dec-2023 04:03:16 UTC] WP_Query Object ( [query] => Array ( [numberposts] => -1 [category] => 0 [orderby] => meta_value_num [order] => ASC [include] => Array ( ) [exclude] => Array ( ) [meta_key] => _elementor_priority [meta_value] => [post_type] => elementor_snippet [suppress_filters] => 1 [meta_query] => Array ( [0] => Array ( [key] => _elementor_location [value] => elementor_body_end ) ) [post_status] => publish [posts_per_page] => -1 [ignore_sticky_posts] => 1 [no_found_rows] => 1 ) [query_vars] => Array ( [numberposts] => -1 [category] => 0 [orderby] => meta_value_num [order] => ASC [include] => Array ( ) [exclude] => Array ( ) [meta_key] => _elementor_priority [meta_value] => [post_type] => elementor_snippet [suppress_filters] => 1 [meta_query] => Array ( [0] => Array ( [key] => _elementor_location [value] => elementor_body_end ) ) [post_status] => publish [posts_per_page] => -1 [ignore_sticky_posts] => 1 [no_found_rows] => 1 [error] => [m] => [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author] => [author_name] => [feed] => [tb] => [paged] => 0 [preview] => [s] => [sentence] => [title] => [fields] => [menu_order] => [embed] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [post_name__in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [post_parent__in] => Array ( ) [post_parent__not_in] => Array ( ) [author__in] => Array ( ) [author__not_in] => Array ( ) [search_columns] => Array ( ) [current_date] => 2023-12-26 [cache_results] => 1 [update_post_term_cache] => 1 [update_menu_item_cache] => [lazy_load_term_meta] => 1 [update_post_meta_cache] => 1 [nopaging] => 1 [comments_per_page] => 50 ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( ) [relation] => AND [table_aliases:protected] => Array ( ) [queried_terms] => Array ( ) [primary_table] => hnr_posts [primary_id_column] => ID ) [meta_query] => WP_Meta_Query Object ( [queries] => Array ( [0] => Array ( [key] => _elementor_priority ) [1] => Array ( [0] => Array ( [key] => _elementor_location [value] => elementor_body_end ) [relation] => OR ) [relation] => AND ) [relation] => AND [meta_table] => hnr_postmeta [meta_id_column] => post_id [primary_table] => hnr_posts [primary_id_column] => ID [table_aliases:protected] => Array ( [0] => hnr_postmeta [1] => mt1 ) [clauses:protected] => Array ( [hnr_postmeta] => Array ( [key] => _elementor_priority [compare] => = [compare_key] => = [alias] => hnr_postmeta [cast] => CHAR ) [mt1] => Array ( [key] => _elementor_location [value] => elementor_body_end [compare] => = [compare_key] => = [alias] => mt1 [cast] => CHAR ) ) [has_or_relation:protected] => ) [date_query] => [request] => SELECT hnr_posts.* FROM hnr_posts INNER JOIN hnr_postmeta ON ( hnr_posts.ID = hnr_postmeta.post_id ) INNER JOIN hnr_postmeta AS mt1 ON ( hnr_posts.ID = mt1.post_id ) WHERE 1=1 AND ( hnr_postmeta.meta_key = '_elementor_priority' AND ( ( mt1.meta_key = '_elementor_location' AND mt1.meta_value = 'elementor_body_end' ) ) ) AND hnr_posts.post_type = 'elementor_snippet' AND ((hnr_posts.post_status = 'publish')) GROUP BY hnr_posts.ID ORDER BY hnr_postmeta.meta_value+0 ASC [post_count] => 0 [current_post] => -1 [before_loop] => 1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 0 [max_num_pages] => 0 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => [is_archive] => [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => [is_tag] => [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => 1 [is_privacy_policy] => [is_404] => [is_embed] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => [is_robots] => [is_favicon] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash:WP_Query:private] => fcaaa9eba5497d90dfee34c557bec773 [query_vars_changed:WP_Query:private] => 1 [thumbnails_cached] => [allow_query_attachment_by_filename:protected] => [stopwords:WP_Query:private] => [compat_fields:WP_Query:private] => Array ( [0] => query_vars_hash [1] => query_vars_changed ) [compat_methods:WP_Query:private] => Array ( [0] => init_query_flags [1] => parse_tax_query ) )
i have try with this code
add_filter( 'relevanssi_search_ok', function( $ok, $query ) { return false; }, 10, 2 );
it’s work fine on the archive page. But after customing code to this, Not work again
add_filter( 'relevanssi_search_ok', function( $ok, $query ) { // Check if it's an archive page for the 'resources' post type if ( is_post_type_archive( 'resources' ) ) { return false; } return $ok; }, 10, 2 );
Ok, so the code has a chance to work, you just need to figure out the right conditional. Clearly, the
is_post_type_archive( 'resources' )
does not returntrue
.That error log is from another query (a search for
elementor_snippet
post type).You can try
add_filter( 'relevanssi_search_ok', function( $ok, $query ) { if ( $query->query['post_type'] ==='resources' ) { return false; } return $ok; }, 10, 2 );
-
This reply was modified 1 year, 2 months ago by
Mikko Saari.
sorry, i have try it, but the result on archive page all post/page not only CPT ‘resources’
Since the filter works if it always returns
false
that tells us there’s a solution. All it takes is finding the right condition that only triggers on that specific search. Unfortunately, I have no way of telling what it is, but inspecting the query parameters in$query
and especially in$query->query_vars
should provide an answer.okay thank you,
How If i want to exclude other post/page except “resources” on result?
with php function/hook, because i want to applying to certain page.If you want the search to only include
resources
posts, set thepost_type
parameter in the query toresources
. There are many ways to manipulate the query parameters;pre_get_posts
orrelevanssi_modify_wp_query
are the most common. See the documentation. -
This reply was modified 1 year, 2 months ago by
- The topic ‘Search Result’ is closed to new replies.