Skip Navigation

[Resolved] Custom taxonomy search filter

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 0 replies, has 3 voices.

Last updated by georgiI 1 month, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2779773
3.PNG
2.PNG
1.PNG

Hi,
The website I'm working on for a client, has other plugin custom taxonomy(listings) categories that do no appear correctly as search filters.
The categories were created trough wp and the listings appear correctly within them. However when I call them in search, they do not show.
They show in search view when created by posts (post form by toolset). They show in account preferences (made by toolset support) and do filter correctly there, however on search view - they do not.

#2779793

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I need to check what's going wrong with your setup and for that I will require admin access details and problem URL where you added your view.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2779923

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share problem URL where you added your views both free and paid.

What is your expected result with free and paid view?

Do I need to login using the frontend user? if yes: please share frontend user access details.

I have set the next reply to private which means only you and I have access to it.

#2780525

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

This is a brief note to let you know that my colleague Minesh is unavailable today but he'll be back on Monday and will update you as soon as possible regarding this issue.

Thank you for your understanding.
Mateus

#2781807

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sorry but how to recognize the free and paid user?

Can you please tell me what view is used for free user and paid user and is there any custom code added for the same?

#2781824

Hi,
payed view 9980 (Search-results-clean-payed)
free is 10097(Search-results-clean).

Only the code you added - all located in custom code (listings-1-week-later and toolset-custom-code). The rest of the code is for prices in search view and featured image.
There are two other views, also made by you - ct-for-views-as-container-search and ct-for-views-as-container. Do not know if they are linked to the problem.

#2782301

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I see following view is used on the following page: payed view 9980 (Search-results-clean-payed)
- hidden link

And for that there is custom filter added as you wanted to filter based on the user selected category with code snippet "toolset-custom-code":

add_filter('wpv_filter_query', 'func_user_selected_city_listing_cat', 99, 3);
function func_user_selected_city_listing_cat($query_args, $setting, $view_id) {

    if ($view_id == 9980 && is_user_logged_in() && pms_is_member()) {

        global $current_user;
        $user_id = $current_user->ID;

        if (isset($_GET['cred_referrer_form_id']) && !isset($_GET['wpv_view_count'])) {

            $user_city = get_user_meta($user_id, 'city', true);
            $user_listing_category = get_user_meta($user_id, 'listing_category', true);

            // Initialize meta_query if it doesn't exist
            if (!isset($query_args['meta_query'])) {
                $query_args['meta_query'] = array();
            }
          
            $query_args['meta_query'] = array(
                  'relation'  => 'OR'
              );  

            if ($user_city) {
                $query_args['meta_query'][] = array(
                    'key' => 'city',
                    'value' => $user_city,
                    'type' => 'CHAR',
                    'compare' => '='
                );
            }

            if ($user_listing_category) {
              
                $query_args['meta_query'][] = array(
                    'key' => 'wpv-listing_category',
                    'value' => $user_listing_category,
                    'type' => 'CHAR',
                    'compare' => '='
                );
              
              
              $query_args['meta_query'][] = array(
                'taxonomy' => 'listing_category',
                'field' => 'id',
                'terms' => $user_listing_category,
                'operator' => 'IN'
              );
            }
        }
    }

    return $query_args;
}

As you wanted to prefilter the view with the user selected term that is why its not showing the term you mention with the screenshot.

Also - as per my solution provided before if you notice the solution with the following ticket, there is tax_query and meta_query added.:
- https://toolset.com/forums/topic/split-user-stored-preference-data-changes-search-results-generic-field-default-value-edit-form/#post-2709430

But as you may notice with the current code, someone added like this, there is no tax_query, I'm not sure why.

$query_args['meta_query'][] = array(
                    'key' => 'wpv-listing_category',
                    'value' => $user_listing_category,
                    'type' => 'CHAR',
                    'compare' => '='
                );

$query_args['meta_query'][] = array(
'key' => 'wpv-listing_category',
'value' => $user_listing_category,
'type' => 'CHAR',
'compare' => '='
);
[/php]

I suggest you should debug this further and correct it as per your requirement.

#2782394

Hi,
The issue is present when both free and payed users use the search. I understand that for payed users the search is based on account, however the free users do not have that, yet the listings do not show correctly. As for payed users when using the search, even though I select one category and city(same from account) sudently they no longer show.

The problem is that if i, as payed user come from account with the predefined preference I do see all categories correctly.
However if I am free user or payed using the search categories filter - they do not show.

#2782402

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Have you try to correct the code as I shared with my previous reply? You can take the latest code from the old ticket where I shared the solution and try to replace with the existing code - do you see it working as expected? if no:

Just to ensure that the "Code Snippet" we added is not causing the issue, what if you disable the code snippet for a moment and do you see it working as expected? if no:

Can I have example with steps to see the issue for free and paid user. Please share both user access details (free and paid).

I have set the next reply to private which means only you and I have access to it.

#2782703

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You shared the first dropdown is for category (taxonomy) listing category and when I checked the view you created:
- hidden link

I see the "Query Filter" is added for the "listing category" as custom field filter. Please check the following screenshot:
- hidden link

What if you try to remove the custom field filter and add the taxonomy filter to your view for the "Listing Category".

Does that helps?

#2782739

Hi,
the issue turned out to be a query filter. Changed it and now it works.