Skip Navigation

[Resolved] AJAX filter not working properly

This support ticket is created 7 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 80 replies, has 3 voices.

Last updated by nadavR 6 years, 7 months ago.

Assisted by: Beda.

Author
Posts
#576873

Beda, another thing. I understand this is a ln issue that might take a lot more looking into. However, my client is not happy with this situation and I can’t afford waiting for over a week until you are back. What can be done so that this bug is squished sooner?

#576875

The process here will continue even if I am away. That is why I mentioned Mohammed. He will replace me if I am not here, and I will fully instruct him on what the issue is.

We will try everything to spot the issue, but I cannot promise there is an easy solution, as this seems to be due to more than a bug in Types. It seems the data was changed at some point.

We will feedback here ASAP.

#576878

Ok. I don’t believe the data was changed - I think it’s called the wrong way. Here’s why:

The filters that are causing the issues are always the ones that are conditioned to appear depending on the Art Form (look up the relevant lines within the loop output to see all these conditionals). For example, in the Music art form, Instrument and Genre are not working properly. However, the fields Type and Country are shared between all Artists regardless of art form, so they appear on all 5 artists lists - without a conditional tag wrapped around them.

Another thing, all the checkboxes were created in Types. None of these options were imported from elsewhere. Some Artists were imported, but not a lot of them, and the checkboxes options were assigned to them later, when everything was already on Types. Again, this worked perfectly and consistently until recently.

Thanks,
Nadav

#576888

Obviously - I may be wrong about this diagnosis as you have looked into this much more extensively. I'm just frustrated as I don't know what would change all the data - and again, my client is not happy about this at all, it's a big organization with plenty of traffic and they need this functionality.

The only 'big' change to the site that's done recently was a WPML install. However, the Artists CPT is still only available in the original English and hasn't been processed to enable translation.

Hope that helps. Thanks for your ongoing assistance,
Nadav

#576912

Here's another piece of information that might be extremely helpful:

I just noticed that once one of the filters that do work is selected (for example, when you change Type to Group) and THEN you select an option from one of the filters we're having problems with (change Genre to Jazz), then it IS working.

This makes me think that after all, everything is defined correctly on my end, it's just that the filter isn't working properly.

Let me know if this helps troubleshoot.

Thanks,
Nadav

#576944

Refining my last message as I keep researching from my end as well:

It seems now to me that the problem can be defined more specifically as a problem with filtering items that have the "Type" field set as "Individual". That's where it all lies, I think.

As I said in my last message, when Type is set to Group or Institution, everything works fine when trying to further filter using Genre and Instrument. However, when Type is set to "All" - and now I'm finding out that it happens on "Individual" as well, filtering doesn't work properly. Something DOES get filtered because the number of returned items is smaller, but not according to the selected choices.

Hope this helps,
Nadav

#577696

Hi, following up as I haven't heard back from you in a few days. Please let me know what the developments are. Thanks!

#579155

Still haven't heard back from you, can you please give me an update? Thanks!

#579374

The solution on your website is the following:

1. Head to the Post Field Group "Options: music artist" and set the checkboxes Field "Instrument" to "When unchecked, don't save anything to the database".
2. Save this Post Fields group
3. Re-save all artist posts
The problem here is you need to resave the meta data, hence a quick exit save will not work.

Then, after this, the Filter works again just fine.

Now, you have around 1600 Artist Pots. You cannot update them manually.

I will ask my Team leader if we can provide a snippet or similar.
Please stand by while I consult this.

#579618

Hi Beda,

I am a little confused. The problem isn't with 'instrument' per se, as this is an issue that affects ALL artforms. What about 'artist type' (part of the Artist Info post field group)? Look at my latest messages (replies #576912 and #576944) in this thread explaining this aspect of the situation.

Thanks,
Nadav

#579754

I understand this. The re-saving of the posts will also re-save those Fields. Yes, first we would need to set them to not save 0 if empty in their settings, as well.

I am actively working with my Team Leader on a solution for this.

The issue is due to unexpected Values in the Meta Value Column of those fields. The options have not a known syntax, as I elaborated a little earlier here.

This needs to be fixed. I was not able to replicate such a syntax with any version of Toolset. Hence, the only that I can suspect is a data corruption, which can be fixed thru a re-save.

We also received your feedback related to this thread via Facebook and I can guarantee that we will do everything to solve this issue for you as smooth as possible. I apologize any delay on the topic.

I will update you here as soon as I have a tested solution for you, that also includes the other Fields.

Thank you for your patience, Nadav.

#579962

Thanks Beda, I appreciate your help. Another thing to keep in mind while working on the solution:

The artists list is sorted newest-to-oldest based on last modified date. That's important since it's a way to see which artists are keeping their profiles 'fresh'. If the solution you include re-saving of posts, will that affect the order? Or is there a way to do it directly to the database without changing the last modified date?

Thanks,
Nadav

#579963

And another thing. If you go to the live site now, to the music artists page, hidden link - you will see that there are new artists that have been added since I gave you the site export. The filter seems to not work even on those new artists, which means, that "corrupt" data is still being added for newer posts. Am I right about this?

#580103

If the solution you include re-saving of posts, will that affect the order?

The way I thought to go, yes. Thank you for informing me on your particular needs here, we then cannot use the mass update approach.

Which is not a solution I had in mind forever. It is for you to move on as fast as possible. I still would analyze the package until found what is the "core" cause in it.

Hence, we will not be able to solve the problem right now with the mass update.

The filter seems to not work even on those new artists, which means, that "corrupt" data is still being added for newer posts. Am I right about this?

Yes, because this is only half the process. The first half, as elaborated earlier, is to change the setting of the field itself from saving 0 to saving nothing if empty. That is also the only reason a mass update is needed after.

Anyway, Mohammed, our Team Leader, discovered an underlying difference in the Database data stored for those fields, and is discussing with the Developer of the Plugin on the best approach considering also the urgency with which we have to threat this issue.

I assume I will have valuable news before the weekend, and hopefully a first solution. I will keep you updated here, and I work Saturday, so in case the information delays I am still here to pass it over.

Please expect my news soon.

#580166

Me and Mohammed investigated this.

1. I personally tested your duplicator with Views 2.2.1 and Types 2.2.2 and it does work exactly the same as now.
Hence, either you updated from a version older than September 27, 2016, or this did not use to work differently.
I assume, according your description, you probably updated from an even younger version.

This seems to have caused a corruption of the data stored.

2. With the current stable versions, using your duplicator, Mohammed crafted a brilliant solution elaborated below.
I tested it according your issue description and could find the problem solved.

I might miss something - please can you test the solution as well (on a Test Site) and let me know if we need to add more items to the Code?
As you will see we included only the one we found broken.
In case we missed some, let us know, we can adjust the script.

This solution would need to be applied to the Theme's Functions PHP File, to immediately re-power your website.

Given that it is not the first time we have issues with sites that use Checkboxes and updated from older versions, we will investigate this.

So, here the code that you need to add to your functions.php file. of your active theme:

add_action('init', 'fix_db');
function fix_db()
{
    $neede_meta_keys = "'wpcf-instrument','wpcf-music-genres'"; //excluded metas ,'wpcf-artist-type','wpcf-country'
    $post_ids = get_posts(array(
        'numberposts' => -1, // get all posts.
        'post_type' => 'artist',
        'fields' => 'ids', // Only get post IDs
    ));
    if (true) {
        global $wpdb;
        $post_ids = implode(',', $post_ids);
        $sql = "SELECT meta_key, meta_value, post_id FROM $wpdb->postmeta WHERE post_id IN ($post_ids) and meta_key IN ($neede_meta_keys)";
        $postmeta = $wpdb->get_results($sql, ARRAY_A);
        if (!empty($postmeta)) {
            foreach ($postmeta as $mKey => $mVal) {
                $serialized_meta = unserialize($mVal['meta_value']);
                $returned_options = [];
                if (!is_array($serialized_meta)) continue;
                foreach ($serialized_meta as $key => $value) {
                    if (is_array($value)) $returned_options[$key] = $value;
                }
                update_post_meta($postmeta[$mKey]['post_id'], $postmeta[$mKey]['meta_key'], $returned_options);
            }
        }
    }
}

Then, navigate to the page with the search.
Then, remove the code and test the search.

Please let me know if this is working for you as well.

Thank you for the patience.

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