Skip Navigation

[Resolved] Views not loading properly

This thread is resolved. Here is a description of the problem and solution.

Problem: A View that should show one result is showing no results, but the "no results found" message is not shown.

Solution: Be sure no custom code is impacting the results. In this case a wpv_filter_query_post_process filter was causing unexpected problems because of typos in the code.

This support ticket is created 3 years, 7 months 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 11 replies, has 2 voices.

Last updated by michaelO-8 3 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1761817
dev_site.PNG
live_site.PNG

I am trying to:

When loading a view I have used for a while, the loop does not display anymore. It should display a loop of custom posts that the author has created. It works on the live site, but not the dev site anymore. I checked for compatibility issues by disabling other plugins and using a standard wordpress theme, but the issue is persisting. Not much has changed on the site other than I updated toolset to the most recent versions recently, but I think it was working properly when I first updated it. I have included a link to a duplicator package below, but if you cannot reproduce the issue, I will provide site access.

For the loop, it does not say that no posts can be found--it just does not load anything within the loop, even if changes are made.

Link to a page where the issue can be seen: hidden link

I expected to see: A list of custom posts "booths" made by the author.

Instead, I got: nothing, not even no results found.

#1761847
Screen Shot 2020-08-30 at 3.58.23 PM.png

Hi, I installed the site locally using your Duplicator package and logged in as the "toolset" user. I created one Booth post as a test, and now when I hit the /my-company-page-standard-view/ page I see that Booth post in the View (see the screenshot). So I'm not really sure what the problem could be. Are you logging in as a specific user? If so, can you share the login credentials so I can check the page as that User?

#1761857
#1761863

Hi Christian,

I also noticed something odd, the view for the page: hidden link seems to work for me, but when putting that view in another page, such as the page:hidden link, the same view seems to stop working.

#1761891

Hi Christian,

Sorry it does seem you are right, the view seems to work correctly for the toolset user. Can you try the user "wsue"?

Thanks!

#1762415
Screen Shot 2020-08-31 at 9.10.02 AM.png

I'm testing user wsue on my local and I'm able to see one result appear in the View. I'm attaching a screenshot of the /my-company-page-standard-view/ page here. I also tested creating a new Page and placing the my-company-page-maryville View on that page. The results are identical. There must be something else going on. Is it possible there is some caching system in place on one of your live environments? That could be a caching plugin in wordpress, or a server-side caching system like Object cache, memcached, varnish, etc? If so, can you clear that cache?

Are you using the User switching plugin to test the wsue User, or actually logging in? If you're using the plugin, can you try actually logging in instead?

Edit: I should mention I was testing User wsue by manually changing their password in the local database.

#1762443

Hi Christian,

It definitely seems like a caching issue, I just can't figure out what would cause it. I did try logging as that user, not switching and the issue persists. Have you tried logging into the site and switching as that user or have you poked around? I am at a loss as to what could be the cause or how to potentially clear the cache.

#1762445

You can try disabling Views cache first. You can do that by modifying the View shortcode like so:

[wpv-view name="your-view-name" cached="off"]

If that doesn't work, I can login and take a look. Please provide login credentials for some admin User here. I've been using my local environment and setting passwords manually as needed.

#1762449
#1762453

Thanks, I'll test and get back to you as soon as I can.

#1762713
#1762773

Okay I see the problem now. There is a custom code snippet interfering with this View. Please go to Toolset > Settings > Custom Code tab and find the snippet "view-dashboard-day" on page 2. Inactivate the snippet and you can test again as wsue to see the View return one result.

I see several issues in this code that need to be resolved.

add_filter( 'wpv_filter_query_post_process', 'show_day' );
 
function show_day( $query) {
     $post_type = get_post_type();
  if($view_id= 34308 && $post_type == "page"){

There is no variable $view_id, and instead of checking for equality you are assigning a value to a variable instead. A double equal sign is required to check equality. Similarly, in the second conditional block:

if($view_id= 34338 && $post_type == "page"){

Again, you are assigning a value to the $view_id variable instead of testing for equality.

Most likely you need to adjust the add_filter line to tell the filter to expect more parameters:

add_filter( 'wpv_filter_query_post_process', 'show_day', 99, 3 );

Then in the function definition, add two expected callback parameters:

function show_day( $query, $view_settings, $view_id ) {

Now in the conditionals, you have access to the $view_id callback parameter as a variable. Be sure to use double equals signs to test equality:

if($view_id == 34308 && $post_type == "page"){
if($view_id == 34338 && $post_type == "page"){

Those are the issues I see at first glance, but you may want to do a more thorough investigation in to this custom code snippet to ensure it works as expected.

#1762811

Hi Christian,

Thank you! I apologize, apparently we had been keeping this snipped deactivated and someone activated it again only recently for testing purposes. I didn't realize this so it didn't occur to me that the custom code could be the issue.

I do have a couple of questions:

1. This code doesn't seem have anything to do with the view that wasn't working, is there a reason why this code would conflict with it?

2. There are definitely some syntax errors in there, but when pressing "save and test", Toolset gives the message "The snippet has been re-run without errors." Does Toolset not check for these kind of errors?

Thanks!

#1762813

1. This code doesn't seem have anything to do with the view that wasn't working, is there a reason why this code would conflict with it?
The conditionals are not logically sound, so the code included in those two conditionals is incorrectly applied to some Views where it should not be applied. In other words the code included in these two conditionals would be executed for any View included on any Page, not only the two Views with those specific IDs. That's the gist of the problem - the conditionals are not accurate and the code is being applied too broadly. The conditionals need to be changed to narrow the scope where this code is applied.

2. There are definitely some syntax errors in there, but when pressing "save and test", Toolset gives the message "The snippet has been re-run without errors." Does Toolset not check for these kind of errors?
There are no actual syntax errors here, I'm afraid. Since you were assigning some value to the $view_id variable with the single equals sign, no syntax errors related to undefined variables would be thrown. It's a sneaky typo that has unintended side effects.

#1762815

Thank you so much, I really appreciated it! I'll be on the lookout for these kinds of issues going forward.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.