Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro User state lost on page updates, filtering and paging

Viewing 10 posts - 1 through 10 (of 10 total)
  • Natalie Gallagher
    #216474

    I have a custom template that displays different fields depending on whether the user has a “Subscriber” role. This template works correctly on the initial page load, and has a category dropdown to filter on, but on all subsequent calls (either ajax enabled or disabled with a Submit button).

    The filters work as expected displaying the appropriate records, but no $user state is being received on the page updates when clicking on the next/previous page or selecting a new category from the filter’s dropdown.

    If I go back to the original URL and load it again, it works as expected and the $user data is present.

    How do I get the $user data to be available to the template in subsequent calls?

    Trevor Moderator
    #216481
    This reply has been marked as private.
    Natalie Gallagher
    #216793
    This reply has been marked as private.
    Trevor Moderator
    #216812

    As an aside, looking at the form setup, this will not be needed, as (Post) Categories do not apply to the Startups Post Type:

    https://www.screencast.com/t/PG7Sh251lGB

    In your code, you are using the

    get_currentuserinfo()

    But that has been deprecated in WordPress for quite some time. You should use

    wp_get_current_user()

    instead. This may help to re-factor the code:

    https://pluginrepublic.com/get-current-user-role-in-wordpress/

    Natalie Gallagher
    #216833

    I refactored the code to not use that, it now is:

    <?php
    if ( current_user_can('subscriber') ){ 
      $subscriber = TRUE;
    	echo "<br><br><br><br><br><br><h1>UserID " . get_current_user_id() . " IS SUBSCRIBER</h1>";
    } else {
      $subscriber = FALSE;
    	echo "<br><br><br><br><br><br><h1>UserID " . get_current_user_id() . " IS NOT A SUBSCRIBER</h1>";
    }
    
    get_header(); 
    ?>

    However, it still does not work. I added code to show the current userID in the template, and the system forgets the UserID when clicking on any of the pager/filter links.

    For example, if you go to the /startups page it shows at the top:

    UserID 15 IS SUBSCRIBER

    but if you click the NEXT link for page 2, it then shows at the top:

    UserID 0 IS NOT A SUBSCRIBER

    showing that it has lost the user state (now user 0 instead of the actual User 15), causing the template to display a non-logged in results page.

    It seems like there is something wrong in your ajax call where it is losing the user state for the session.

    Trevor Moderator
    #216836

    I will need to refer this to the plugin developer, Ross, for his input.

    Natalie Gallagher
    #216838

    Btw, Feel free to edit the template file for testing purposes (it’s not a production site and I’ve got backups). Just let me know what you changed so I can keep track of it going forward.

    Thanks

    Ross Moderator
    #217145
    This reply has been marked as private.
    Natalie Gallagher
    #217154

    I tested the site with adding random variables to the query string and it did NOT show the user as logged out. Screen recording of the test here:

    https://www.loom.com/share/75f0511697064f118f5cb0f3670f53e3

    You may have seen a cached page when you did your test, but if you hard-reload the page or go to the URL directly as shown in the video, it does in fact preserve the user state.

    I didn’t recreate the filters in the video (somebody else set it up originally) but it seems to be working properly except for the S&F user issue.

    If you want to work through this together, you can reach me at 1-443-910-3677 (cell/text) and we can debug in real-time. If you want to give me a date/time we can discuss, I’ll try to make myself available so we can get this resolved.

    Do you have this working on other sites where the data is rendered varying based on the logged in user, or is this a new thing we’re trying to do?

    Thanks,

    – Brian

    Ross Moderator
    #217459

    Hi Brian

    I think I see the issue.

    When you search, the page goes to a http version of the site, where you are no longer logged in.

    This is because in your Results URL you have put a URL with just http://

    This then sends you to a logged out version of the site, where the user ID can only be 0

    Because you hide the admin bar I don’t think you noticed you were looking at a logged out version of the site?

    Updating the Results URL to use https should do the trick.

    Thanks

Viewing 10 posts - 1 through 10 (of 10 total)

The forum ‘Search & Filter Pro’ is closed to new topics and replies.