Skip Navigation

[Resolved] ugly long winded url. js failed me , other options ?

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Tagged: 

This topic contains 16 replies, has 2 voices.

Last updated by Akhil 6 years ago.

Assisted by: Waqar.

Author
Posts
#1162663

Hi. look at my search url:

hidden link

note the field : landed-house-storey_min=&landed-house-storey_max=&land-size_min=&land-size_max is NOT related to the searching category at all. i am using js to hide and display the field. i know this is how it works, any other workaround for this ?

#1162672

this is my code, its working ,

jQuery(document).ready(function($) {
     $("div[data-target='#collapse-res-feat']").parent('div.panel-info').hide(); 
     
     // check landed house > open landed tab
     $('input[value="landed-houses"]').on('change', function() {
     
        if($('input[value="landed-houses"]:checked').length > 0){
        $("div[data-target='#collapse-res-feat']").parent('div.panel-info').show(); 
          $(".nl_landed_fields").show();
        }
      else{
        $("div[data-target='#collapse-res-feat']").parent('div.panel-info').hide(); 
        $(".nl_landed_fields").hide();
          }
      })
     
        })

is there anyway to hide the field search url too? display only when its used ,something like that ..

#1162674
#1162708

Hi Dee,

Thanks for asking! I'd be happy to help.

When the search results are set to update on page reload, the URL parameters are used for any subsequent searches/page reloads, too.

For this reason, I'll not recommend filtering out even the empty parameters from the search URLs, as this can lead to unexpected results.

Have you considered using the AJAX based results, which won't reload the page? This way you can make the search form, not to update and use the parameters in URL at all.
( screenshot: hidden link )

Note: if you decide to use AJAX approach, you'll need to update your existing script to show/hide search fields/section slightly, because the page won't be reloading everytime the search is performed.

In that case, you can move your conditional script in a new function, e.g.


function SearchFormFn()
{
	// code to show or hide form fields conditionally
};

// run the code in the function SearchFormFn on page reload
jQuery(document).ready(function($) {
	SearchFormFn();
});

The above code will execute the function on first load of the search from.

To make it also execute, when the search results are updated after the AJAX call, you can add the function name SearchFormFn in the "will run after updating the results" field, under the "Javascript settings".
( screenshot: hidden link )

I hope this helps and let me know if you have any questions or concerns around this approach.

regards,
Waqar

#1162721

Hi waqar, thanks . beleive i love to use ajax but my setup cant .
i read somewhere one the ajax limitations. maybe im in there.
also for ajax need to load into one single view? im using layout and wordpress archive inside. will this work ?

#1162735

here i've implemented here: hidden link

but note that even before this ajax was not working for me?
do you see any script conflict from the console panel ? i cant.

#1162753

i just found out it does work when logged in in frontend, as guest doesnt work, what could be the issue ?

#1162757

Hi Dee,

Thanks for writing back and for sharing the findings.

If you'll check the search (as a guest and not as a logged-in user), you'll see that AJAX call is failing with a 403 (forbidden) status code.
( screenshot: hidden link )

You'll also note that if a visitor tries to access the WordPress' default AJAX URL directly ( hidden link ), it redirects to the login page ( hidden link ), which shouldn't be happening.

This suggests that either some third-party plugin, custom code or server's policy is blocking the AJAX calls for non-logged-in visitors.

You can start troubleshooting, by temporarily disabling all non-Toolset plugins and switching to a default WordPress theme like Twenty Seventeen.

In case the issue still persists, you can also consult your hosting support team, to check if there are any server policies in place, to block the AJAX calls for visitors.

regards,
Waqar

#1162761

Hi,

You'll also note that if a visitor tries to access the WordPress' default AJAX URL directly ( hidden link ), it redirects to the login page ( hidden link ), which shouldn't be happening.

>> this is from my custom snippet for security .
it just redirect any login request to my custom login page.
perhaps i need to exclude something in the code ?
i have the snippet here: hidden link

//<em><u>hidden link</u></em>
add_action( 'wp_login_failed', 'pippin_login_fail' );  // hook failed login
function pippin_login_fail( $username ) {
     $referrer = $_SERVER['HTTP_REFERER'];  // where did the post submission come from?
     // if there's a valid referrer, and it's not the default log-in screen
     if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
          wp_redirect(home_url() . '/?login=failed' );  
	   // let's append some information (login=failed) to the URL for the theme to use
          exit;
     }
}
#1162773

is there anyway can have another copy/relocate the admin ajax file ?

#1162789

if there is no other solution i guess we are back to my first question ,

#1162803

Hi Dee,

That function that you shared, shouldn't result in a conflict with the AJAX calls.
( if this function was responsible for this redirection, we would see "?login=failed" appended at the end of the login URL, when accessing hidden link )

The default AJAX feature and its URL is a standard feature that is controlled through WordPress itself. It is designed in a way that theme and plugin authors can make use of it in a convenient, standardized and a secure manner.

I'm afraid, relocation or customization of that AJAX URL is not an option because it would break all AJAX base functionalities added through WordPress, theme and plugins (Toolset included).

I'll recommend to follow the troubleshooting suggestions from my earlier message.
( https://toolset.com/forums/topic/ugly-long-winded-url-js-failed-me-other-options/#post-1162757 )

regards,
Waqar

#1162804
#1162805

Hi Waqar ,

i am sure one of my custom snippets causing this. ill update soon. UNLESS you saying snippets cannot cause any of this issue then im liittle worried,

#1162809

Hi Dee,

I apologize if my message resulted in a confusion.

I only meant that the particular function that you referenced, shouldn't conflict with the AJAX calls. It is possible that there is be some other custom code involved, which is specifically why I suggested testing this with a default WordPress theme, which would rule out any custom code conflict.

I'll wait for an update from you when you've tested this with all other (non-Toolset) plugins disabled and without any custom code.

Note: once you've found the responsible code that is adding this redirection, you can update it to exclude the AJAX calls, as shown in the thread you found:
https://wordpress.stackexchange.com/questions/26100/redirect-out-of-wp-admin-without-losing-admin-ajax-php

regards,
Waqar