I'm using FacetWP to create search result pages for my site. I need to use the following URL to engage the plugin and create the search results I need:
https://www.mywebsite.com/basketball-camps/?fwp_sport=basketball
Because the equal sign is a reserved character the url is truncated when published and the equal sign is removed like this:
https://www.mywebsite.com/basketball-camps/?fwp_sportbasketball
It doesn't produce the search results with the equal sign removed. Any suggestions?
Farid answers:
FacetWP provide Ajax search functionality are you not using that?
Also if you are using the FacetWP results page then can you let me know how you configured its page for the default search results?
Thanks
Farid comments:
If your site is live then it would be great if you share its URL with me?
Cesar Contreras answers:
You have already read this documentation? maybe can be solved your problem.
https://facetwp.com/documentation/facetwp_query_args/
Francisco Javier Carazo Gil answers:
Good evening,
This string is a URL with a GET parameter with a value:
https://www.mywebsite.com/basketball-camps/?fwp_sport=basketball
And this one is a URL with a GET parameter without a value:
https://www.mywebsite.com/basketball-camps/?fwp_sportbasketball
= is a character reserved to assign values to a variable.
Not sure what do you want.
Kyle answers:
Depending on where you are having the issue, you can trying putting in the HTML entity = where the = sign goes. Additionally you can try preventing WP from autoformatting HTML with this plugin https://wordpress.org/plugins/preserved-html-editor-markup-plus/
User179135 comments:
Sorry. I tried both of these and neither worked. The HTML entity still removed the equal sign. The plugin didn't change anything. Thank you though.
Kyle comments:
When you say "the equal sign is a reserved character the url is truncated " where are you putting this URL that it is being truncated?
User179135 comments:
I'm editing the permalink on the page.
Kyle comments:
Okay, I think you're going about this the wrong way. Instead would you consider this:
Source: https://facetwp.com/pre-select-facet-choices/
Code:
add_filter( 'facetwp_preload_url_vars', function( $url_vars ) {
if ( 'basketball-camps' == FWP()->helper->get_uri() ) {
if ( empty( $url_vars['make'] ) ) {
$url_vars['sport'] = array( 'basketball' );
}
}
return $url_vars;
} );
Kyle comments:
That goes in your functions.php file
Kyle comments:
Sorry, the code had a typo
add_filter( 'facetwp_preload_url_vars', function( $url_vars ) {
if ( 'basketball-camps' == FWP()->helper->get_uri() ) {
if ( empty( $url_vars['sport'] ) ) {
$url_vars['sport'] = array( 'basketball' );
}
}
return $url_vars;
} );
User179135 comments:
So put that code into the functions.php file?
Kyle comments:
Yes, but be careful and do it over FTP and not the admin encase you make mistake
User179135 comments:
Sorry. It didn't work. Basically nothing happened. I think its the right idea though.
When I copy and paste the URL into the address bar the page pulls up perfectly. Because of the equals sign permalinks or custom links don't work. There has to be a way to call the URL.
Kyle comments:
I sent you a PM
Kyle comments:
Nevermind, I guess you can't do that anymore. If you I can access your site directly and get this done for you, I've worked with FacetWP a lot of the years so should only take a few minutes once I'm in there.
mod mi answers:
I'm not quite sure what the problem might be, but you could try url encode when creating the links like this for example:
$search = "fwp_sport=basketball";
echo '<a href="/basketball-camps/?"'.urlencode($search).'">search</a>"
Hai Bui answers:
Hi, Can you let me know where is the URL truncated? Where/how do you use this URL?
User179135 comments:
I have produced a page that's coded for FacetWP to return search results.
https://www.mywebsite.com/basketball-camps/?fwp_sport=basketball
This url pulls the results and places them on the page. However, Wordpress Permalinks are truncating the URL removing the equal sign.
https://www.mywebsite.com/basketball-camps/?fwp_sportbasketball
The search results don't pull. I've tried encoding per recommendings (%3D) but it doesn't work either.
Hai Bui comments:
The permalink can't contain that "?fwp_sport=basketball". If you have a template for this page and you want it to always use the "basketball" filter, you can add
$_GET['fwp_sport'] = 'basketball';
at the beginning of the template.
Hai Bui comments:
I'm sorry my last solution won't work. I think it will require javascript as FacetWP will look for the parameter in the URL. If you provide me FTP access, I can help you do it. It's not a simple answer.
User179135 comments:
I can provide FTP access.
Bob answers:
Are you trying to add query variable at the page or post url in backend?
you want only this link to be added in menu?
If so I think you should try Custom Link menu (https://easywpguide.com/wordpress-manual/appearance/updating-the-menu/adding-a-custom-link-menu-item/)
or may be add query arg will help
https://developer.wordpress.org/reference/functions/add_query_arg/
it will be good If you can explain properly then we can help.
User179135 comments:
I'm adding the url at the page level by changing the permalink.
I tried adding it to a custom link in the menu. Didn't work.
Bob comments:
this is also something about adding query vars
https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars
Bob comments:
I just added in Custom link Appearance > Menu and it worked.
can you tell me how are you adding it?
Bob comments:
Please try this code in functions.php of your theme,
add_action( 'wp', 'process_post' );
function process_post() {
if( is_page( 'basketball-camps' ) ) {
// process $_POST data here
if(!isset($_GET['fwp_sport']))
$genre_url = add_query_arg('fwp_sport', 'basketball', get_permalink());
wp_redirect($genre_url);
}
}
Bob comments:
Please try this code in functions.php of your theme,
add_action( 'wp', 'process_post' );
function process_post() {
if( is_page( 'basketball-camps' ) ) {
// process $_POST data here
if(!isset($_GET['fwp_sport']))
$genre_url = add_query_arg('fwp_sport', 'basketball', get_permalink());
wp_redirect($genre_url);
}
}
Bob comments:
Please note after adding above code you do not need to add anything in permalink.
It will add querystring automatically to "basketball-camps" page
Echeverri answers:
you tried to receive the parameter with $_GET['fwp_sport'] and then you do the query? try that